create_table.ots (57.9 KB)
The attached spreadsheet template tries to generate the SQL command which creates a new table to hold the spreadsheet data.
- Paste-special your values with column labels to A1 of the first sheet and follow the instructions in the yellow box.
- Go to the next sheet and follow the instructions in the yellow box. Choose column types as small as possible and as large as necessary. Sheet “Types” has some hints.
- Copy the concatenated code in the last cell or copy the cell range in column B from
CREATE TABLE ...(
until
"ID" INTEGER GENERATED BY DEFAULT AS IDENTITY);
- Paste the code in Base’s SQL window and execute.
Executing steps 3 and 4 from my unmodified sample data generates a new, empty table with 4 columns of type DATE, VARCHAR(10), DECIMAL(6,2) and an auto-ID.
Tested with embedded Firebird and HSQL.
I reduced the availlable types to the commonly used simple types.
Having the auto-ID column at last position, this column is out of the way when pasting the sheet data.
After you are finished with database range “Data” on the first sheet, the formulas on the second sheet test if the columns are consistently filled with numbers or text.
Formatting is completely out of scope, i.e. the formulas do not try to examine if a column has dates or times or fixed decimals. Just take care that your dates and times on the data sheet are formatted according to ISO 8601 before you copy them to your database.
Red cells indicate inconsistent data types in a column. Fix the data, not anything else.