How the CSV to SQL INSERT works
The CSV is read with a standard (RFC 4180) parser: quoted fields may contain the delimiter, line breaks and doubled quotes,
and blank lines are skipped. The first row supplies the column names. Empty or repeated names are made unique, and rows
with fewer values than the header get NULL for the missing columns.
Before writing anything, every column is checked: if all of its values (apart from NULLs) are plain numbers, the column is
written without quotes; otherwise every value in it is written as a string, with single quotes doubled, N'...'
for non-ASCII text on SQL Server and escaped backslashes on MySQL. That keeps values such as postal code
01067 exactly as they are. Rows are then grouped into INSERT ... VALUES statements of the size you
choose. The SQL is only generated as text and is never run.
How to use the CSV to SQL INSERT
- Paste CSV with a header row into the input box, open a .csv file, or select Load example.
- Enter the table name, choose the dialect, the delimiter (or leave it on Detect automatically) and how many rows go into each INSERT.
- Choose how empty cells and the text NULL are treated, and tick Include CREATE TABLE if you want a table definition too.
- Select Convert to SQL, or press Ctrl + Enter (Cmd + Enter on a Mac), then copy the SQL or download it as a .sql file.
Example
This CSV, with table name customers and PostgreSQL:
id,name,postal_code,credit_limit
1,"Smith, Jane",01067,2500.00
2,Seán O'Connor,,NULL
produces:
INSERT INTO "customers" ("id", "name", "postal_code", "credit_limit")
VALUES
(1, 'Smith, Jane', '01067', 2500.00),
(2, 'Seán O''Connor', NULL, NULL);
Common use cases
- Importing a spreadsheet saved from Excel or Google Sheets as CSV into a database table.
- Turning a CSV export from another system into a script that can be reviewed and run later.
- Seeding lookup tables such as countries, currencies or product categories.
- Sharing a small dataset as a SQL script that anyone can run without an import wizard.
Common errors and how to fix them
- Unterminated quoted field starting on line N
- A field opened with a double quote but never closed it, so the parser reads the rest of the file as one value. Find that line and add the closing quote, remembering that a quote inside a quoted field is written twice.
- The CSV has a header row but no data rows
- Only the column names were pasted. Add at least one row of values below the header.
- The first data row was treated as column names
- The first row is always read as the header. If your file has no header, type the column names into the Columns box instead.
- Numbers or dates were quoted as text
- Values are taken from the file as written, and CSV carries no type information. Set the column types for the target table yourself, and check the generated statements before running them.
Frequently asked questions
How does the tool decide whether a value is a number?
A column is written without quotes only if every value in it (ignoring NULLs) is a plain decimal number such as 42, -7.5 or 1e3. Values with leading zeros like 00123, thousands separators or currency symbols make the whole column text, so postal codes and phone numbers keep their exact form.
How are empty cells and NULL handled?
With Empty values as NULL ticked, an empty cell becomes NULL; otherwise it becomes an empty string ''. With Treat NULL text as NULL ticked, a cell containing just NULL (in any letter case) becomes NULL instead of the string 'NULL'.
What CSV formats are supported?
Standard CSV with a header row: fields in double quotes can contain the delimiter, line breaks and doubled quotes (""). The delimiter can be a comma, semicolon, tab or pipe, or detected automatically. Empty or repeated header names are renamed, for example to column_2 or name_2.
How are special characters escaped?
Single quotes are doubled, so O'Connor becomes 'O''Connor'. For SQL Server, text with non-ASCII characters such as é or ü is written as N'...' so it is stored correctly in NVARCHAR columns, and for MySQL backslashes are escaped as well.
Does the tool run the INSERT statements?
No. It only writes SQL text for you to review and run yourself. It never connects to a database, and your CSV is not uploaded to our server.