How to Convert CSV to SQL INSERT Statements

Turn a CSV into SQL INSERT statements with your own table name, for MySQL, PostgreSQL, SQLite or SQL Server, with values safely quoted. No upload, no sign-up.

Updated 5 min read By CodingEagles
Free tool CSV to SQL Converter Generate SQL INSERT statements from a CSV, with your table name. Open tool

You have data in a CSV and you need it in a database table. Importing through a GUI works for a one-off, but when you want the load to be repeatable, scriptable, or part of a migration, INSERT statements are what you reach for. Writing them by hand for more than a few rows is tedious and error-prone.

The short version: paste a CSV, set the table name and your database, and copy the generated SQL. The CSV to SQL tool runs on your device, so nothing is uploaded.

What the conversion produces

Each data row becomes an INSERT statement (or one row of a batched insert) targeting the table you name, with columns taken from the header row. A file like this:

name,age,city
Kim,27,Seoul
Ana,34,Lisbon

becomes something like:

INSERT INTO "people" ("name", "age", "city") VALUES ('Kim', 27, 'Seoul');
INSERT INTO "people" ("name", "age", "city") VALUES ('Ana', 34, 'Lisbon');

Notice that the ages are unquoted while the names and cities are. That distinction is the part that is fiddly to get right by hand, and it matters: quote a number and some columns reject it; forget to quote text and the statement fails.

Quoting and escaping, done for you

Two details cause most hand-written INSERT errors. The first is text that contains an apostrophe, like O'Hara, which ends the string early unless the apostrophe is doubled. The second is identifiers, the table and column names, which each database quotes differently. The conversion doubles apostrophes in values and quotes identifiers the way your chosen database expects, so the output runs as-is.

Choosing your options

A few switches tailor the output:

  • Database dialect sets how names are quoted: backticks for MySQL, brackets for SQL Server, double quotes elsewhere.
  • Batch mode emits one multi-row INSERT ... VALUES (...), (...) instead of a statement per row, which loads faster for large files.
  • CREATE TABLE adds a table definition above the inserts, so you can create and populate in a single paste.
  • Empty cells as NULL writes blank values as NULL rather than an empty string, when that distinction matters to your schema.

How to convert CSV to SQL

Step 1: Add the CSV

Paste CSV text into the tool or drop in a file. The first row is read as the column names.

Step 2: Set the table and dialect

Type the target table name and pick your database. Turn on batching or a CREATE TABLE if you want them.

Step 3: Copy the SQL

Copy the statements straight into your client, a migration file or a script.

If you need a different interchange format rather than SQL, the CSV to XML tool produces well-formed XML from the same data. And to load the CSV into a spreadsheet instead of a database, the CSV to Excel converter builds a typed workbook.

Frequently asked questions

Which databases do the statements work with?
You can target MySQL, PostgreSQL, SQLite or SQL Server, plus a standard mode for anything else. The main difference is how table and column names are quoted, with backticks for MySQL and brackets for SQL Server, so the statements run without edits in your client.
How are text and numbers handled?
Values that look like plain numbers are written without quotes so they fit numeric columns, while text is wrapped in single quotes with any apostrophes escaped. That keeps a name like O'Hara from breaking the statement.
Can it create the table too?
Yes. There is an option to add a CREATE TABLE statement above the inserts, with a column per header, so you can stand up a table and load it in one go. You can also batch every row into a single multi-row INSERT.
Is my CSV uploaded?
No. The file is read and converted on your own device. Nothing is uploaded, nothing is stored, and the data never leaves your browser.

Ready to try it?

Generate SQL INSERT statements from a CSV, with your table name. Free, in-browser, and 100% private — your data never leaves your device.

Open the CSV to SQL Converter