CSV to SQL Converter (INSERT Statement Generator)
Convert CSV files into SQL INSERT and CREATE TABLE statements. Supports MySQL, PostgreSQL, and SQLite dialects with automatic column type detection (integer, decimal, string). Conversion runs entirely in your browser; no data is sent to a server.
| Delimiter |
|
|---|---|
| Use first line as header | |
| Table name | |
| SQL dialect |
|
| Also generate CREATE TABLE statement | |
| Treat empty values as NULL | |
| Combine rows into a single INSERT statement |
Enter CSV data to see the generated SQL here.
How a CSV row maps to an INSERT statement
| One CSV row | name,age,city |
|---|---|
| Resulting INSERT statement | INSERT INTO `my_table` (`name`, `age`, `city`) VALUES ('Alice', 30, 'Tokyo'); |
When the first line is used as a header, each subsequent row becomes one INSERT statement naming the header columns. Columns detected as integer or decimal are output as unquoted numbers, and all other columns are output as single-quoted strings.
Tips
- Column types (integer, decimal, string) are inferred automatically by inspecting every data row in that column. If even one value is non-numeric, the entire column is treated as a string type.
- Enabling "Combine rows into a single INSERT statement" produces one `INSERT INTO ... VALUES (...), (...), (...);` statement, reducing the number of executions needed to load large datasets.
- MySQL quotes identifiers with backticks (`), while PostgreSQL and SQLite use double quotes ("). The quoting style switches automatically based on the selected SQL dialect.
- Disabling "Treat empty values as NULL" outputs empty strings ('') for string columns and NULL for numeric columns instead.
Frequently Asked Questions
Side Note — Why bundled INSERT statements are faster
The "combine rows into a single INSERT statement" option this tool offers (`INSERT INTO t VALUES (1,'a'), (2,'b'), ...;`) can execute considerably faster than issuing one INSERT statement per row. This is because it reduces the overhead of parsing and planning each SQL statement, and the cost of transaction commits that would otherwise repeat once per statement.
That said, MySQL has a `max_allowed_packet` limit, and PostgreSQL has a similar communication buffer cap, so cramming too many rows into a single INSERT statement can exceed those limits and cause an error. In practice, splitting statements every few hundred to a few thousand rows is the common approach.
Loading CSV data into a test database is often called "seeding" in development workflows, and many web frameworks — Laravel's seeders and factories among them — provide dedicated mechanisms for exactly this task. A quick converter like this one remains handy for small-scale verification or data migration that does not warrant setting up that full machinery.