CSV to SQL Converter
Convert CSV to SQL INSERT statements, with an optional CREATE TABLE, for MySQL, PostgreSQL and SQLite. Keeps leading zeros, escapes MySQL backslashes, handles quoted fields and NULLs.
- Runs in your browser
- Your data never leaves your browser
- Free · No Sign-Up
Scan with WeChat to share this tool
Examples, details and FAQ Worked examples, how it compares with other tools, and answers to common questions.
How Values Are Written
- Empty CSV fields produce
NULL. - A column whose non-empty cells are all plain numbers (
42,-7,19.90) is written without quotes. A plain number has no leading zero, no+, no exponent and at most 15 digits. - Every other column is written as quoted strings, including its numbers, so
02134,1e5and a 20-digit card number keep their exact text. MySQL, PostgreSQL and SQLite all convert a quoted number when the target column is numeric. - Single quotes are doubled (
O”Brien) in every dialect. In MySQL, backslashes are doubled too: MySQL’s default SQL mode reads\ninside a string as a newline (MySQL 8.4 Reference Manual, String Literals, Table 11.1). PostgreSQL withstandard_conforming_stringson (the default since 9.1, PostgreSQL 4.1.2.1) and SQLite store backslashes as written. - Cells beyond the header get extra columns named
column_3,column_4and so on, and the status line lists them. Short rows are padded withNULL.
Example: Quotes, Leading Zeros and Empty Fields
Input (SQLite, batch mode, table customers):
id,name,zip,note
1,"O'Brien, Pat",02134,
2,Lee,10001,"path C:\new"
INSERT INTO "customers" ("id", "name", "zip", "note") VALUES
(1, 'O''Brien, Pat', '02134', NULL),
(2, 'Lee', '10001', 'path C:\new');
The quoted field “O’Brien, Pat” keeps its comma. The empty note becomes NULL. 02134 makes the zip column a text column, so 10001 is quoted as well. Run against SQLite 3, SELECT zip FROM customers returns 02134 and 10001.
The same input in MySQL doubles the backslash, so the stored value is still path C:\new:
id,name,zip,note
1,"O'Brien, Pat",02134,
2,Lee,10001,"path C:\new"
INSERT INTO `customers` (`id`, `name`, `zip`, `note`) VALUES
(1, 'O''Brien, Pat', '02134', NULL),
(2, 'Lee', '10001', 'path C:\\new');
If your server runs with NO_BACKSLASH_ESCAPES in sql_mode, backslashes are ordinary characters; use the PostgreSQL or SQLite output for that server instead.
Example: CREATE TABLE
With Add CREATE TABLE ticked, column types are chosen from the values: whole numbers become INTEGER (INT in MySQL, BIGINT beyond 2,147,483,647), numbers with a decimal point become DOUBLE PRECISION (DOUBLE in MySQL, REAL in SQLite), everything else TEXT. PostgreSQL:
order_id,amount,paid_at
1001,19.90,2026-09-30
1002,5,
CREATE TABLE "orders" ("order_id" INTEGER, "amount" DOUBLE PRECISION, "paid_at" TEXT);
INSERT INTO "orders" ("order_id", "amount", "paid_at") VALUES
(1001, 19.90, '2026-09-30'),
(1002, 5, NULL);
Change the types before running it when they matter: money belongs in NUMERIC / DECIMAL, and dates such as paid_at in DATE or TIMESTAMP. No primary key or constraints are added.
Example: More Cells Than Headers
sku,qty
A-1,3,fragile
B-2,5
INSERT INTO "stock" ("sku", "qty", "column_3") VALUES ('A-1', 3, 'fragile');
INSERT INTO "stock" ("sku", "qty", "column_3") VALUES ('B-2', 5, NULL);
The status line reports the added column column_3. Rename it in the header row if you want a real name.
Limits
- The delimiter is a comma, and the first row is always the header. Semicolon or tab separated files need converting first.
- Types are guessed from the text only. Dates, booleans and
1e5are strings. - Table and column names are quoted as single identifiers, so
public.usersbecomes one name with a dot in it. - Large files are converted in the browser tab in one pass; for millions of rows use the database’s bulk loader (
LOAD DATA,COPY,.import).
FAQ
What does this tool do?
Converts CSV data into SQL INSERT statements, and optionally a CREATE TABLE statement. The header row gives the column names; every data row becomes a row of values, quoted and escaped for the chosen dialect.
Which SQL dialects are supported?
MySQL (backtick identifiers, backslashes in strings doubled), PostgreSQL and SQLite (double-quote identifiers, backslashes written as they are). The INSERT syntax is the same in all three.
How are NULL values handled?
Empty fields become NULL (without quotes). A field that contains only spaces is a string, not NULL. The tool cannot produce an empty string ''.
Why is 02134 quoted but 10001 sometimes not?
A column is written as numbers only when every non-empty cell in it is a plain number: no leading zeros, no plus sign or exponent, at most 15 digits. 02134 is not, so the whole zip column is quoted and the leading zero survives.
Is any data sent to a server?
No. All conversion happens in your browser using JavaScript. No CSV data is transmitted.