CSV to SQL INSERT
Turn a small block of comma-separated rows into one SQL INSERT statement per data row, ready to paste into a query editor.
INSERT INTO my_table (name, value) VALUES ('A', '1');
INSERT INTO my_table (name, value) VALUES ('B', '2');How to use this tool
- 1
Type the destination table name into the top field (it is dropped into the generated INSERT exactly as typed).
- 2
Paste your CSV into the text box, keeping the header row first so its names become the column list.
- 3
Read the INSERT statements that appear below as you type, with one statement per data row.
- 4
Select the generated SQL and copy it into your database client or migration script to run it.
How does this CSV to SQL INSERT generator work?
This tool reads the first line of your CSV as a header and uses those comma-separated names verbatim as the column list. For every following line it emits one statement of the form INSERT INTO table (col1, col2) VALUES ('v1', 'v2'); joining the rows with newlines. Splitting is deliberately simple: it breaks each line on every comma and trims surrounding spaces, so it has no real CSV parser. That means a value containing a comma, a quoted field like "Smith, Jr.", or a newline inside a cell will split into the wrong number of columns. Every value is wrapped in single quotes, and single quotes inside a value are escaped by doubling them (O'Brien becomes 'O''Brien'), which is the standard SQL string-escaping rule. Because every value is quoted, numbers come out as string literals such as '42' rather than bare 42, and empty cells become '' rather than NULL — most engines coerce numeric strings on insert, but check your column types. The output uses only plain ANSI INSERT syntax, so it runs in MySQL, PostgreSQL, SQLite, SQL Server and others without changes.
Common use cases
Seeding a few rows of test or fixture data into a local development database without writing the INSERTs by hand.
Converting a small spreadsheet export of lookup values (statuses, categories, country codes) into a migration script.
Drafting INSERT statements for a quick demo or tutorial where the data is short and contains no commas inside fields.
Reshaping a handful of rows copied from a CSV file into SQL you can paste into a query console.
Generating a starting point for a data-load script that you will then hand-edit to add NULLs or fix column types.
Teaching or learning SQL INSERT syntax by watching how column lists and quoted values are assembled from rows.
Frequently asked questions
Does my CSV data get uploaded anywhere?▼
Does it correctly handle commas inside quoted fields?▼
How are single quotes and apostrophes handled?▼
Why are my numbers wrapped in quotes?▼
What happens to empty cells and NULLs?▼
Is this good for very large CSV files?▼
Which databases does the generated SQL work with?▼
Related tools
JSON to CSV Converter
Convert JSON arrays to CSV.
CSV to JSON Converter
Convert CSV to JSON arrays.
Binary to Hex Converter
Convert binary numbers to hexadecimal.
Hex to Binary Converter
Convert hexadecimal to binary numbers.
Decimal to Binary Converter
Convert decimal numbers to binary, hex, octal.
ASCII to Hex Converter
Convert text to ASCII hex codes and back.