CSV to SQL Insert Generator

Turn CSV rows into INSERT statements (and an optional CREATE TABLE) for PostgreSQL, MySQL, SQLite or SQL Server.

SQL output
CREATE TABLE IF NOT EXISTS "customers" (
  "id" INTEGER,
  "name" TEXT,
  "zip" TEXT,
  "price" DOUBLE PRECISION,
  "active" BOOLEAN,
  "signup" DATE
);

INSERT INTO "customers" ("id", "name", "zip", "price", "active", "signup") VALUES
  (1, 'O''Brien', '02134', 9.5, TRUE, '2024-01-15'),
  (2, 'Lee, Ann', '90210', 12, FALSE, '2024-02-01'),
  (3, 'Bob', '10001', NULL, TRUE, NULL);

3 rows, 6 columns: id (integer), name (text), zip (text), price (real), active (boolean), signup (date)

Or drop a .csv file here

or click to browse — max 10 MB, read locally

When to generate SQL from a CSV

Native bulk loaders such as PostgreSQL's COPY, MySQL's LOAD DATA INFILE or SQLite's .import are the fastest way to import large files, but they need file access on the server and are often disabled on managed databases. When you want to seed a development database, add a few hundred rows to a migration, paste data into a SQL console, or share a reproducible fixture in a pull request, plain INSERT statements are simpler: they run anywhere and can be reviewed line by line.

The hard part is getting the details right: quoting column names that contain spaces or reserved words, escaping apostrophes and backslashes, not turning 02134 into 2134, and producing NULLs where cells are empty. This generator handles those for four common databases.

How to use it

  1. Paste CSV with a header row into CSV input, drop a .csv file, or click Load example.
  2. Type the Table name (use schema.table to include a schema) and choose the Dialect.
  3. Leave Delimiter on Auto-detect unless the result has the wrong number of columns.
  4. Pick Rows per INSERT and tick Include CREATE TABLE, Detect column types, Empty cells as NULL and Trim whitespace as needed.
  5. Check the column summary and any warnings under the output, then click Copy SQL or Download .sql.

Worked example

The built-in example contains an apostrophe, a quoted comma, a zip code with a leading zero and empty cells:

id,name,zip,price,active,signup
1,O'Brien,02134,9.5,true,2024-01-15
2,"Lee, Ann",90210,12,false,2024-02-01
3,Bob,10001,,true,

With table customers, PostgreSQL and the default options, the output is:

CREATE TABLE IF NOT EXISTS "customers" (
  "id" INTEGER,
  "name" TEXT,
  "zip" TEXT,
  "price" DOUBLE PRECISION,
  "active" BOOLEAN,
  "signup" DATE
);

INSERT INTO "customers" ("id", "name", "zip", "price", "active", "signup") VALUES
  (1, 'O''Brien', '02134', 9.5, TRUE, '2024-01-15'),
  (2, 'Lee, Ann', '90210', 12, FALSE, '2024-02-01'),
  (3, 'Bob', '10001', NULL, TRUE, NULL);

Switching to MySQL changes the quotes to backticks (`customers`); SQLite stores the booleans as 1/0 and the date as TEXT; SQL Server uses [customers], BIT, NVARCHAR(MAX) and drops IF NOT EXISTS, which its CREATE TABLE does not support.

What the options do

  • Detect column types — numbers and booleans are written unquoted only when the whole column fits that type. Off: every value is a quoted string and every column is text.
  • Empty cells as NULL — off writes an empty string '' instead. The text null in a cell is always kept as the string 'null'.
  • Trim whitespace — removes spaces around each value. Header names are always trimmed; empty or duplicate headers become column_N or get a _2 suffix.
  • Rows per INSERT — 1 gives one statement per row (easiest to debug); larger batches import faster.
  • Rows with fewer cells than the header are padded with empty values and rows with more are truncated; both cases are reported as warnings.

Limitations

  • Type detection only recognises ISO dates (2024-01-15); dates such as 01/15/2024 stay text.
  • No primary keys, indexes, VARCHAR lengths or NOT NULL constraints are generated.
  • MySQL escaping assumes the default SQL mode; with NO_BACKSLASH_ESCAPES enabled, doubled backslashes would be stored literally.
  • Input is limited to 10 MB. For millions of rows, use your database's native CSV import instead.

Tips

  • Wrap the generated script in a transaction (BEGIN; … COMMIT;) so a failing row does not leave a half-imported table.
  • Need JSON for an API instead of SQL? Use the CSV to JSON converter. To tidy hand-written queries, try the SQL Formatter.
  • Starting from an Excel workbook? Convert it first with Excel to CSV.

Frequently Asked Questions

Which SQL dialects are supported?

PostgreSQL, MySQL/MariaDB, SQLite and SQL Server. Each dialect gets its own identifier quoting ("col", `col` or [col]), string escaping, boolean literals and column type names.

How are quotes and backslashes in values escaped?

Single quotes are doubled in every dialect (O'Brien becomes 'O''Brien'). For MySQL, backslashes are also escaped (C:\temp becomes 'C:\\temp') because MySQL treats the backslash as an escape character by default. SQL Server strings use the N'' prefix to keep Unicode text intact.

Will zip codes or IDs with leading zeros be kept?

Yes. A column is only treated as numeric when every non-empty value is a plain number without leading zeros, so 02134 is inserted as the string '02134'. Turn off "Detect column types" to quote every value.

How does the CREATE TABLE statement choose column types?

Each column gets the narrowest type that fits all its values: integer (BIGINT above the 32-bit range), real, boolean (true/false), date (YYYY-MM-DD), datetime (YYYY-MM-DD HH:MM[:SS]) or text. Review the types before running it; the tool cannot guess lengths, keys or constraints.

What does "Rows per INSERT" do?

It groups several rows into one INSERT … VALUES statement, which imports much faster than one statement per row. SQL Server accepts at most 1000 rows per VALUES list, so larger batches are capped automatically.

Is my CSV uploaded to a server?

No. The CSV is parsed and the SQL is generated in your browser; files you drop are read locally and never sent anywhere.