How to convert Excel to SQL
Updated · 3 min read
Product catalogues, price lists and migration data often arrive as Excel workbooks. Instead of exporting to CSV and fighting import wizards, convert the sheet directly into SQL INSERT statements. Excel already knows which cells are numbers, dates and text, so the generated SQL — and the optional CREATE TABLE — use the right types.
- Upload or drop the
.xlsxworkbook and pick the sheet. - Make sure the first row holds column names; simple names without spaces are easiest to query.
- Choose the SQL dialect and table name in Options, and tick Add SQL CREATE TABLE if the table does not exist yet.
- Copy the statements into your SQL client or download the
.sqlfile.
Example
Excel input
| employee_id | full_name | department | salary | hired |
|---|---|---|---|---|
| 1001 | Nadia Amrani | Finance | 5400 | 2021-04-12 |
| 1002 | Lucas Martin | 4800 | 2023-09-01 |
SQL output
CREATE TABLE IF NOT EXISTS `employees` (
`employee_id` INTEGER,
`full_name` VARCHAR(255),
`department` VARCHAR(255),
`salary` INTEGER,
`hired` DATE
);
INSERT INTO `employees` (`employee_id`, `full_name`, `department`, `salary`, `hired`) VALUES
(1001, 'Nadia Amrani', 'Finance', 5400, '2021-04-12'),
(1002, 'Lucas Martin', NULL, 4800, '2023-09-01');The empty department cell becomes NULL rather than an empty string, dates become ISO DATE values, and the header row becomes quoted column names.
Your data stays on your device. The conversion runs in JavaScript inside this tab — files and pasted text are never uploaded to DataSwitch Pro.
From sheet to table
The first row becomes the column list and every following row becomes one row of values. Keep headers short and database-friendly — order_date rather than Date of order (dd/mm) — or rename them in Excel first. Empty rows are skipped, and blank or duplicate headers are renamed automatically so the statement remains valid.
Types from Excel cells
Because Excel cells are typed, numbers arrive as numbers, TRUE/FALSE as booleans, dates as ISO strings and text — including codes with leading zeros — as quoted strings. Empty cells become NULL. With Add SQL CREATE TABLE, these types also drive the column definitions: INTEGER, DOUBLE, BOOLEAN, DATE or VARCHAR(255)/TEXT.
Tips for multi-sheet workbooks
Convert one sheet per table using the sheet menu. If tables reference each other through foreign keys, insert the parent tables first (for example customers before orders). For very large sheets, consider exporting to CSV with the Excel to CSV converter and using your database's bulk loader.
Convert Excel to SQL in code
For one-off files the tool above is quickest. To automate the same task in a script or pipeline, these snippets are a good starting point.
Python (pandas + SQLAlchemy)
import pandas as pd
from sqlalchemy import create_engine # pip install pandas openpyxl sqlalchemy pymysql
engine = create_engine("mysql+pymysql://user:password@localhost/company")
df = pd.read_excel("employees.xlsx", sheet_name="Staff")
df.to_sql("employees", engine, index=False, if_exists="append")
Frequently asked questions
Which SQL databases are supported?
MySQL/MariaDB, PostgreSQL, SQLite and SQL Server. Choose the dialect in Options and identifiers, booleans and strings are written accordingly.
Do empty cells become NULL?
Yes. Empty Excel cells are written as NULL.
Can I convert several sheets?
One at a time — choose each sheet from the sheet menu and copy its SQL.
Are formulas exported?
The calculated results of formulas are exported, not the formulas themselves.
Is the spreadsheet uploaded?
No. The workbook is read in your browser, so salary lists and customer data stay on your device.