Convert Excel to SQL Online
Turn an Excel sheet into a CREATE TABLE and INSERT script, with column types guessed from the cells. The workbook is opened in your browser and never uploaded.
Drop a CSV or Excel file here
CSV · XLSX · XLS · XLSM · XLSB
Ready to download as a binary file.
How to convert Excel to SQL
Three steps from stock.xlsx to a .sql script.
1. Drop the workbook
Drop an .xlsx, .xls, .xlsm or .xlsb file, or paste cells copied from Excel.
2. Check it in the grid
Look for columns that mix numbers and text (a TBD in a price column): they become TEXT. Remove a totals row at the bottom too, or it is inserted as data.
3. Set dialect and table
Pick the dialect, type a table name, tick CREATE TABLE or DROP TABLE IF EXISTS, then copy or download data.sql.
Example: Excel in, SQL out
A small stock sheet with a spaced header ("Unit Price") and a formula column (=B2*C2).
| A | B | C | D | |
|---|---|---|---|---|
| 1 | SKU | Unit Price | Qty | Value |
| 2 | A-100 | 2.5 | 40 | =B2*C2 |
| 3 | B-220 | 12.75 | 4 | =B3*C3 |
CREATE TABLE `stock` (
`SKU` TEXT,
`Unit_Price` DOUBLE,
`Qty` INT,
`Value` INT
);
INSERT INTO `stock` (`SKU`, `Unit_Price`, `Qty`, `Value`) VALUES
('A-100', 2.5, 40, 100),
('B-220', 12.75, 4, 51);The spaced header "Unit Price" becomes `Unit_Price`, and the Value column holds the calculated results (100 and 51) as INT.
What changes between Excel and SQL
Column types are guessed
In this example SKU is TEXT, Unit_Price is DOUBLE, Qty and Value are INT. The rule: whole numbers give INT, a decimal point gives DOUBLE, anything else TEXT, dates included (other dialects use their own names, such as INTEGER and REAL).
Values
The first row is inserted as ('A-100', 2.5, 40, 100): numbers bare, text in single quotes.
One INSERT for all rows
All rows go into a single multi-row INSERT. SQL Server accepts at most 1,000 rows per VALUES list, so split larger scripts there. Identifiers are quoted per dialect: `backticks` for MySQL, "double quotes" for PostgreSQL and SQLite, [brackets] for SQL Server.
One sheet at a time
Only the sheet whose tab is active goes into the SQL: here "Stock". Click the "Suppliers" tab to convert that sheet instead.
When to convert Excel to SQL
- Importing a spreadsheet someone maintains by hand into the application database.
- Moving a lookup table (prices, regions, tax rates) from Excel into SQL once, then maintaining it there.
Excel to SQL in JavaScript
TabularJS reads every sheet; the snippet picks one by name. Then one INSERT is built, with the same quoting rules as this page.
import tabularjs from 'tabularjs';
const { worksheets } = await tabularjs('stock.xlsx');
const sheet = worksheets.find((ws) => ws.worksheetName === 'Stock');
const [header, ...rows] = sheet.data; // Value arrives as "=B2*C2"
const id = (name) => '`' + String(name).trim().replace(/[^A-Za-z0-9_]/g, '_') + '`';
const value = (v) => {
if (v == null || String(v).trim() === '') return 'NULL';
return isNaN(v) ? `'${String(v).replace(/'/g, "''")}'` : String(v).trim();
};
console.log(`INSERT INTO ${id('stock')} (${header.map(id).join(', ')}) VALUES\n` +
rows.map((row) => `(${header.map((_, i) => value(row[i])).join(', ')})`).join(',\n') + ';');Unlike this page, TabularJS does not calculate formulas: Value comes back as "=B2*C2". Dates arrive as serial numbers (45414 is 2024-05-02).
Frequently asked questions
Will the SQL include the Excel formulas?
No. SQL has no cell formulas, so the calculated values are inserted. If a value must stay computed, use a generated column or a view in the database instead.
Can I load several sheets into several tables?
One sheet at a time: switch to the tab, change the table name, and copy the SQL for each sheet.
Are formulas exported?
Their results are. The grid calculates each formula and the output uses the calculated value. If you read the file with TabularJS in code instead, formulas come back as text and are not calculated.
Can I insert into a table that already exists?
Yes. Untick CREATE TABLE and type the existing table name (it defaults to my_table; the example uses stock). The column names in the INSERT are the cleaned-up headers, so they must match your table's columns.
Does stock.xlsx get uploaded when I convert it to SQL?
No. The workbook is opened in your browser and never uploaded.