RevealTheme logo

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. 1

    Type the destination table name into the top field (it is dropped into the generated INSERT exactly as typed).

  2. 2

    Paste your CSV into the text box, keeping the header row first so its names become the column list.

  3. 3

    Read the INSERT statements that appear below as you type, with one statement per data row.

  4. 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?
No. The conversion runs entirely in your browser with JavaScript. Nothing you type into the table name or CSV box is sent to a server, so it is safe for sensitive data.
Does it correctly handle commas inside quoted fields?
No. It splits every line on each comma with no CSV parser, so a value like "Smith, Jr." is treated as two columns and the row will have the wrong number of values. For files with quoted fields, embedded commas, or embedded newlines, use a real CSV-to-SQL importer or your database's native loader.
How are single quotes and apostrophes handled?
Each value is wrapped in single quotes and any single quote inside it is doubled, which is the standard SQL escaping rule. So O'Brien becomes 'O''Brien' and inserts correctly.
Why are my numbers wrapped in quotes?
Every value is emitted as a quoted string literal, so 42 becomes '42'. Most databases implicitly convert a numeric string when inserting into a numeric column, but if yours does not, remove the quotes around those values manually.
What happens to empty cells and NULLs?
An empty cell becomes an empty string '' rather than NULL, because the tool always quotes values. If you need real NULLs, replace the relevant '' with NULL after generating the statements.
Is this good for very large CSV files?
It works row by row and will produce one INSERT per line, but for thousands of rows it is far slower to run than a bulk loader. Prefer your database's native LOAD DATA INFILE (MySQL) or COPY FROM (PostgreSQL) for large imports.
Which databases does the generated SQL work with?
The output is plain INSERT INTO ... VALUES syntax with no engine-specific features, so it runs unchanged in MySQL, PostgreSQL, SQLite, SQL Server and most other relational databases.

Related tools