CSV to SQL INSERT Generator
This tool turns a CSV with a header row into SQL INSERT statements. It quotes names and values correctly, writes empty cells as NULL and can group rows into batches.
- Free, no sign-up
- Nothing is sent to a server
- Worldwide
How to use CSV to SQL INSERT Generator online
- Paste the CSV. Include the header row.
- Name the table. And pick the separator and quoting.
- Set the options. Numbers, NULL and batch size.
- Copy the SQL. Copy or save the statements.
Why use this free CSV to SQL INSERT Generator
- Header row as column names
- MySQL or standard quoting
- NULL for empty cells
- Batches of rows
- Leading zeros kept
- Share by link
From a spreadsheet to a table
To load a CSV file into a database, one way is to write INSERT statements. The tool reads the header row as the column names and each following row as a record, and writes INSERT INTO statements with the table name you give. You can then run the statements in your database client.
Quoting
Names are wrapped in backticks for MySQL and MariaDB or in double quotes for standard SQL. Text values are wrapped in single quotes, and a single quote inside a value is doubled, so O'Neil is written as 'O''Neil'. For MySQL the backslash is also doubled, since MySQL treats it as an escape character by default.
A worked example
The CSV for a table called people has 3 rows and 3 columns. It becomes 1 statement:\nINSERT INTO people (id, name, city) VALUES
(1, 'Ann', 'Oslo'),
(2, 'O''Neil', 'Rome'),
(3, NULL, 'Paris');\nThe empty city of the third row is NULL, and the quote in O'Neil is doubled. Numbers are written without quotes because the numbers option is on.
Options
Numbers can be left unquoted or all values can be quoted as text; a number with a leading zero, such as 007, is always quoted, so the zeros are not lost. Empty cells can be written as NULL or as an empty string. Rows are grouped into batches, 100 per statement by default, or one statement per row if you set 1.
Use with care
The tool makes text only and never connects to a database. Check the statements before you run them, and run them first on a copy of your data. The column types are decided by your table, not by the tool. For large files, load data with the import feature of your database, which is faster than INSERT statements.
Using the tool
The result shows under the boxes and refreshes as you edit. Undo and redo step back through your earlier text.
CSV to SQL INSERT Generator: frequently asked questions
How do I turn a CSV into INSERT statements?
How are quotes in values handled?
What about empty cells?
Can I get one statement per row?
Does it connect to my database?
Does the CSV to SQL INSERT Generator keep a copy of my text?
Is there a way to reuse the CSV to SQL INSERT Generator result?
Related searches for CSV to SQL INSERT Generator
- CSV to SQL INSERT Generator online
- free CSV to SQL INSERT Generator
- CSV to SQL INSERT Generator online free
- CSV to SQL INSERT Generator for mobile
- CSV to SQL INSERT Generator without sign up
- convert csv to sql insert generator
- csv to sql insert generator converter
- CSV to SQL INSERT Generator – Text & Writing Tools
CSV to SQL INSERT Generator is a free online tool on MAITBOX, in the Text & Writing Tools group. It runs in your browser, so what you type is not sent to a server. It works on Android and iPhone, and on Windows, Mac and Linux, with no download and no account.