CSV to SQL INSERT Statements
CV-11Paste CSV and get INSERT statements for T-SQL, PostgreSQL, MySQL or SQLite. Names are quoted for the dialect, text is escaped, and empty cells can become NULL.
Runs in your browser. Nothing is uploaded.
CSV (optional first line: -- table: dbo.Customers)
SQL
How to use it
- Paste your CSV into the input box, or open a .csv file (up to 5 MB) or drop it on the box.
- Choose the Dialect and a Table name. For your own name, put -- table: dbo.Customers as the first line of the input.
- Set Rows per INSERT, whether empty cells become NULL, and whether numbers stay unquoted.
- Copy the SQL or download it as a .sql file, read it over, then run it in your database tool.
What the INSERT statements look like
The header row supplies the column list, and each later row becomes a row of values. With 100 rows per INSERT, you get one statement holding up to 100 rows, written as INSERT INTO ... VALUES (...), (...). Choose 1 for one statement per row. Names are quoted for the dialect: [brackets] for T-SQL, double quotes for PostgreSQL and SQLite, backticks for MySQL. A schema name works, as in dbo.Customers. Without a header row there is no column list, so the values must match the table's column order.
How values are written
Text is single-quoted with each quote doubled, so O'Brien is written 'O''Brien'. For MySQL, backslashes are doubled as well, which assumes the default mode. T-SQL text with non-ASCII characters is written as N'...' so Unicode survives. Numbers of up to 15 digits with no leading zero are left unquoted; everything else, including 007 and longer numbers, stays quoted text so it is not changed. An empty cell becomes NULL by default, or '' if you untick that option.
Limits to know about
This writes data, not a schema. It does not create the table, guess column types or run anything, and a CSV cannot say whether an empty cell was a missing value or an empty string. SQL Server accepts at most 1,000 rows in one INSERT ... VALUES, so T-SQL output is split at 1,000 even if you pick All rows. A NUL character in a cell is an error. Always read the generated SQL before you run it on a live database.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
The CSV has a header row but no data rows, so there is nothing to insert. | Only one row was found, and it was treated as the header. | Add data rows, or untick First row is header if that row is data. |
The table name "a..b" has an empty part. Use a name like users or dbo.users | The -- table: line has two dots in a row, or starts or ends with a dot. | Write the name as table or schema.table. |
A value contains a NUL character (U+0000), which SQL string literals cannot hold | A cell holds a null character that cannot be written inside a SQL string. | Remove the character from that cell in the CSV. |
A quoted field is never closed (missing closing ") | A field starts with a double quote, but the text ends before the closing quote, so the parser cannot tell where the field stops. | Add the missing closing quote, or double any quote that belongs inside the text, as in "". |
Questions people ask
How do I convert a CSV file to SQL INSERT statements?
Paste the CSV into the input box, pick your database under Dialect and a table name, and the INSERT statements appear. Copy them or download a .sql file. Read the SQL over before you run it. Nothing is uploaded.
How do I set the table name?
Pick one from the Table name list, or put a first line such as -- table: dbo.Customers above your CSV. That line is read as a setting, not data, and overrides the list. The name can be table or schema.table.
How are quotes and special characters escaped?
A single quote inside text is doubled, so O'Brien becomes 'O''Brien'. In MySQL, backslashes are doubled too. T-SQL text with non-ASCII characters gets the N prefix. A null character in a cell is reported as an error.
Why is 007 in quotes but 7 is not?
Numbers with up to 15 digits and no leading zero are left unquoted, so 7 becomes 7. A value like 007 keeps its zeros only as text, so it is quoted. Untick Leave numbers unquoted to quote every value.
What happens to empty cells?
By default an empty cell becomes NULL. Untick Empty cell becomes NULL to insert an empty string instead. A CSV cannot say whether a blank was missing or empty, so check which one your column needs.
How many rows go in one INSERT statement?
You choose: 1, 100, 500, 1,000 or all rows. SQL Server allows at most 1,000 rows per INSERT ... VALUES, so T-SQL output is split at 1,000 even if you pick All rows. The other dialects use your number as it is.
About this tool
Writes INSERT statements with a column list taken from the header (no header row means no column list, so the values must match the table's column order). Names are quoted for the dialect: [brackets] for T-SQL, double quotes for PostgreSQL and SQLite, backticks for MySQL; schema.table works. To use another table name, put a first line such as -- table: dbo.Customers above your data; it overrides the Table name list. Text is single-quoted with quotes doubled; in MySQL, backslashes are doubled too (this assumes the default mode, not NO_BACKSLASH_ESCAPES), and T-SQL text with non-ASCII characters is written as N'...'. Numbers up to 15 digits without a leading zero are left unquoted unless you turn that off; everything else, including 007 and longer numbers, stays quoted text. A cell that is empty becomes NULL by default, so a real empty string cannot be told apart from a missing value; turn that off to insert ''. SQL Server allows at most 1,000 rows per INSERT, so T-SQL output is capped there. It does not create the table, guess column types or run anything. Check the output before running it on a live database.