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.
About the CSV to SQL Converter
Writing INSERT statements by hand, one row at a time, is not a realistic option once you need to load a real CSV file into a database. This tool reads your CSV and converts each row into an INSERT statement automatically. It scans every data row in a column before deciding whether that column is an integer, a decimal, or a string, so it can also generate a matching CREATE TABLE statement whenever you need one.
It supports MySQL, PostgreSQL, and SQLite, switching the identifier quoting style and type names to match whichever dialect you pick. Single quotes inside your values are escaped automatically using the standard SQL convention, so the output can be run as-is. Every bit of the conversion happens locally in your browser, and your CSV content is never sent anywhere.
How to turn CSV rows into INSERT statements
- Paste your CSV Paste your CSV data into the input box. If it is tab-separated, switch the delimiter option to Tab first.
- Set the table name and dialect Enter the name of the destination table and choose the database dialect you are targeting. Identifier quoting updates automatically to match.
- Choose your output options Decide whether to also generate a CREATE TABLE statement, treat empty cells as NULL, and combine multiple rows into a single INSERT statement.
- Copy and run it Copy the generated SQL and paste it into your database client. For very large datasets, consider running it in smaller batches.
Tips for getting more out of it
- 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.
Ways to use the CSV to SQL converter
Preparing seed data for testing
Turn test data you built in a spreadsheet directly into INSERT statements. It is a fast way to handle small-scale verification without writing a full framework seeder.
Migrating master data
Convert a CSV exported from an old system into statements ready to load into a new database, complete with a matching CREATE TABLE statement.
Spotting unexpected column types
Reviewing the automatically detected types can reveal columns with stray values, such as a column you expected to be numeric coming out as text.
Comparing dialect syntax side by side
Run the same CSV through each dialect option to see how identifier quoting and type names differ between MySQL, PostgreSQL, and SQLite in practice.
SQL loading terms
- INSERT statement
- The SQL command used to add a row to a table, mapping column names to the values being inserted.
- CREATE TABLE statement
- The SQL command used to create a new table, defining its column names and types. You need this when the destination table does not exist yet.
- SQL dialect
- The syntax differences between database products, such as which symbol quotes identifiers and how type names are spelled.
- NULL
- A special value that represents the absence of data. It is distinct from an empty string, which is why you need to decide how blank cells should be treated.
- Escaping
- The process of making a character with special syntactic meaning be treated as a literal character instead, which applies here to single quotes inside your values.
- Bulk insert
- Loading multiple rows using a single INSERT statement instead of one statement per row, which reduces parsing and commit overhead and runs faster.
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.