CSV to SQL
Drop your CSV below to get SQL insert statements. The conversion happens inside this browser tab, so the file is never uploaded to a server.
How to convert CSV to SQL
- Choose your CSV file, or drag it onto the box below.
- Set the table name and pick your SQL dialect.
- Download the .sql file and run it against your database.
Identifiers are sanitised too
Table and column names are stripped of characters that would need escaping, and a leading digit gets an underscore prefix. The result is quoted regardless, so a column named order or select does not collide with a reserved word.
Empty values become NULL, not empty strings
A missing cell is written as NULL rather than an empty string, which keeps IS NULL checks meaningful. If you need empty strings instead, they are distinguishable in the source CSV by being explicitly quoted.
Questions
Are quotes in my data escaped?
Yes. Single quotes are doubled, so a value such as O'Brien produces 'O''Brien' rather than a syntax error or, worse, a statement that changes meaning. Never assemble SQL by string-joining a CSV yourself for exactly this reason.
How are column types decided?
From the data, per column. A column is INTEGER only if every value is a whole number, NUMERIC if every value is numeric, BOOLEAN if every value is true or false, and TEXT otherwise. A single non-numeric value makes the whole column TEXT, which is the safe direction to err in.
Which dialects are supported?
ANSI quoting with double quotes, which suits PostgreSQL, SQLite and most others, and MySQL with backticks. The statements themselves are standard.
Why are the INSERTs batched?
Rows are grouped 100 at a time into multi-row INSERT statements. One statement per row is far slower to execute on a large file, and a single statement for the entire file can exceed the maximum packet size.
Is my file uploaded anywhere?
No. The SQL is generated in JavaScript inside your own browser tab. Nothing is sent to a server, stored or logged.
Background
For why CSV files lose leading zeros, arrive as one long column, or show strange characters, see what a CSV file is. This page is one of the free CSV converter tools — all of them run in your browser and none of them upload your file.