How to Convert CSV to SQL INSERT Statements
Convert CSV or Excel-exported data into SQL CREATE TABLE and INSERT statements for MySQL, PostgreSQL, SQLite, SQL Server, or Oracle, with type inference and safe batching.
On this page
CSV files are convenient for spreadsheets and data exchange, but relational databases need typed tables and SQL statements.
To load a small or medium CSV dataset through a SQL script, you usually need two things:
- a
CREATE TABLEstatement - one or more
INSERT INTO ... VALUESstatements
You can generate both with the free CSV to SQL Converter.
The converter runs in your browser and supports SQLite, MySQL/MariaDB, PostgreSQL, SQL Server, and Oracle.
Example CSV
Suppose you export this spreadsheet as CSV:
id,name,department,salary,active
1,Ada Lovelace,Engineering,95000.50,true
2,Grace Hopper,Platform,102500.00,true
3,Alan Turing,Research,110000.00,false
A database import script needs to turn the header into column names and each row into SQL values.
For SQLite, a generated result could look like:
CREATE TABLE employees (
id INTEGER,
name TEXT,
department TEXT,
salary REAL,
active INTEGER
);
INSERT INTO employees (
id,
name,
department,
salary,
active
)
VALUES
(1, 'Ada Lovelace', 'Engineering', 95000.50, 1),
(2, 'Grace Hopper', 'Platform', 102500.00, 1),
(3, 'Alan Turing', 'Research', 110000.00, 0);
Other database dialects use different data types and identifier rules, so the output should match the database you plan to load.
Convert CSV to SQL online
Open the CSV to SQL Converter.
You can either paste CSV/TSV text or choose a local file.
Then:
- choose the delimiter, or leave auto-detection enabled
- select the target database
- set the destination table name
- choose whether empty values become
NULLor empty strings - choose a batch size
- click Convert to SQL
The tool previews the parsed data and generates SQL that you can copy or download as a .sql file.
CSV from Excel or Google Sheets
You can paste tabular data copied directly from Excel or Google Sheets.
When data comes from a spreadsheet, tabs or commas are both common separators. The converter can detect:
- comma
- tab
- semicolon
- pipe
Quoted values containing commas or line breaks are also handled.
For example:
id,name,notes
1,"Smith, Alice","Line one
Line two"
2,Bob,"No notes"
should remain three columns rather than being split incorrectly at the comma inside "Smith, Alice".
Type inference
A CSV file does not contain database column types.
The converter inspects values across each column and selects a suitable SQL type for the selected database.
Typical inferred categories include:
- integers
- large integers
- decimal numbers
- booleans
- dates
- timestamps
- text
Type names differ by database.
For example, a boolean-like column might become a native BOOLEAN in PostgreSQL but use a different representation in another dialect.
Always review generated DDL before running it against a production database.
Empty values: NULL or empty string?
These two CSV rows are not necessarily equivalent:
1,Alice,
2,Bob,""
Depending on the source system, an empty field can mean either:
- no value: SQL
NULL - an intentionally empty text value:
''
The SQLiz converter lets you choose how empty fields should be treated.
That choice matters for filters, constraints, uniqueness, and application behavior.
Why batch INSERT statements?
Instead of generating one SQL statement per row:
INSERT INTO employees VALUES (...);
INSERT INTO employees VALUES (...);
INSERT INTO employees VALUES (...);
it is often more efficient to group multiple rows:
INSERT INTO employees (id, name)
VALUES
(1, 'Alice'),
(2, 'Bob'),
(3, 'Carol');
The converter can generate batched inserts so large CSV files do not become thousands of tiny statements.
Database-specific limits still matter. See SQL Bulk and Batch Insert by Database for differences between MySQL, PostgreSQL, SQLite, SQL Server, and Oracle.
Import the generated SQL into SQLite
If SQLite is your target, you can send the generated SQL directly to the SQLite Playground.
That lets you:
- verify that the table is created
- inspect inferred data types
- query the imported rows
- test indexes or transformations
- download the resulting SQLite database
Everything runs locally in the browser.
Format the generated script
For long output, use the SQL Formatter to normalize indentation and keyword casing.
Formatting does not prove that the SQL is valid for your database version, so you should still test the script before production use.
When CSV to SQL is the right approach
Generating SQL is useful when:
- you need a readable migration or seed script
- the dataset is small enough to review
- you want the import in source control
- you need to move spreadsheet data into a development database
- you want a reproducible test fixture
For very large datasets, native bulk-loading tools are usually better than giant SQL scripts.
Start with the CSV to SQL Converter when you need a quick browser-based conversion.