CSV to SQL Converter

CSV Input
1
SQL Output
1

Last updated:

Jsonic's CSV to SQL converter turns a CSV file into a CREATE TABLE statement and batched INSERT statements for PostgreSQL, MySQL, SQLite or SQL Server. Column types are inferred from every row (integers, decimals, booleans, dates, timestamps, text), headers become safe snake_case column names, empty cells become NULL, and quoted fields with commas or line breaks are parsed correctly. It runs in your browser — the CSV is never uploaded.

Example

id,name,signup_date,monthly_spend,active
1,Alice Martin,2026-01-05,49.00,true
2,Bob O'Neil,2026-02-11,0,false

becomes (PostgreSQL):

CREATE TABLE "customers" (
  "id" INT,
  "name" TEXT,
  "signup_date" DATE,
  "monthly_spend" NUMERIC,
  "active" BOOLEAN
);

INSERT INTO "customers" ("id", "name", "signup_date", "monthly_spend", "active") VALUES
  (1, 'Alice Martin', '2026-01-05', 49.00, TRUE),
  (2, 'Bob O''Neil', '2026-02-11', 0, FALSE);

Type mapping by database

CSV valuesPostgreSQLMySQLSQLiteSQL Server
Whole numbersINT / BIGINTINT / BIGINTINTEGERINT / BIGINT
DecimalsNUMERICDECIMAL(18,6)REALDECIMAL(18,6)
true / falseBOOLEANBOOLEANINTEGER (1/0)BIT (1/0)
2026-01-05DATEDATETEXTDATE
2026-01-05T10:30:00ZTIMESTAMPDATETIMETEXTDATETIME2
Anything elseTEXTVARCHAR(50/255) or TEXTTEXTNVARCHAR(50/255/MAX)

Loading big files with the database's own importer

-- PostgreSQL (psql)
\copy customers FROM 'customers.csv' WITH (FORMAT csv, HEADER true)

-- MySQL
LOAD DATA LOCAL INFILE 'customers.csv' INTO TABLE customers
  FIELDS TERMINATED BY ',' ENCLOSED BY '"' IGNORE 1 LINES;

-- SQLite (sqlite3 shell)
.import --csv --skip 1 customers.csv customers

Working with JSON instead of CSV? Use JSON to SQL, or convert with CSV to JSON first.

How to convert CSV to SQL

  1. Paste your CSV, including the header row.
  2. Choose PostgreSQL, MySQL, SQLite or SQL Server and enter a table name.
  3. Click Convert.
  4. Copy the SQL or download the .sql file and run it in your database.

FAQ

How do I convert a CSV file to SQL?

Paste the CSV (with a header row) into the input panel, pick your database — PostgreSQL, MySQL, SQLite or SQL Server — enter a table name, and click Convert. You get a CREATE TABLE statement with a column for each header and INSERT statements for every row. Copy them or download a .sql file and run it in your database client.

How are column types chosen?

Each column is checked across every row. Whole numbers become INT (or BIGINT above 2,147,483,647), decimals become NUMERIC/DECIMAL, true/false becomes BOOLEAN (BIT on SQL Server), YYYY-MM-DD becomes DATE and ISO timestamps become TIMESTAMP/DATETIME. If any value in a column does not fit, the whole column becomes text, so nothing is lost. Values with leading zeros such as ZIP codes (02134) stay text.

How are empty cells, quotes and commas handled?

Empty cells become NULL. Single quotes are escaped by doubling them (O'Brien → 'O''Brien'). Quoted CSV fields can contain commas, double quotes ("") and line breaks, and are read correctly. The delimiter is detected automatically: comma, semicolon, tab or pipe.

Why are the INSERT statements split into batches?

One multi-row INSERT per 500 rows keeps statements fast and under database limits — SQL Server, for example, allows at most 1,000 rows in a single VALUES list.

How are column names generated?

Header names are converted to safe snake_case identifiers ("First Name" → first_name, "orderID" → order_id) and quoted for your dialect: "double quotes" for PostgreSQL and SQLite, `backticks` for MySQL, [brackets] for SQL Server. Duplicate or empty headers get a numeric suffix.

Is my CSV uploaded?

No. Parsing and SQL generation run in your browser. The file never leaves your device.

What about very large CSV files?

For files with hundreds of thousands of rows, use your database's bulk loader instead of INSERT statements: COPY in PostgreSQL, LOAD DATA INFILE in MySQL, .import in the sqlite3 shell, or BULK INSERT in SQL Server. You can still generate the CREATE TABLE here from the first few thousand rows.