CSV to SQL converter
Paste CSV, TSV or JSON, or open an Excel .xlsx file, and get INSERT
statements and an optional CREATE TABLE for SQL Server, PostgreSQL, MySQL, SQLite
or Oracle. It all runs in your browser: nothing you paste or open is sent anywhere.
Drop a .csv, .tsv, .json 或者 .xlsx file anywhere
on this side. Workbooks are read one sheet at a time. Legacy .xls 和 .ods
files are not read: save them as .xlsx or CSV, or copy the range in your spreadsheet
app and paste it here, since spreadsheets paste as tab-separated text.
Parsed table
Showing the last table that parsedThe dropdown under each column name overrides its detected type; 自动 keeps the guess. The line under it is the column type the CREATE TABLE gets.
更多选项
Oracle output is always one INSERT per row.
How the conversion works
The converter reads your data the way a database import would. It splits the text into rows
and columns, picks a type for every column, and writes each row out as an INSERT
with the quoting rules of the engine you chose.
- Parsing. Delimited text follows RFC 4180, so quoted fields keep their commas, escaped double quotes (
"") and line breaks. Commas, tabs, semicolons and pipes are all detected, and a comma inside a quoted header cell doesn't count toward the guess. If a quote never closes, the tool tells you which line it opened on instead of quietly folding the rest of the file into one value. A paste that starts with[is read as JSON: either an array of objects, where the keys become column names, or an array of arrays. JSON numbers keep the digits they were written with, so12345678901234567890和1.10arrive unchanged. - Excel files. 一个
.xlsxfile is unpacked in the browser and read one sheet at a time; pick the sheet when the workbook has several. Cells keep their stored values: text, numbers at full precision,TRUE/FALSE, and dates and times converted from Excel's day serials (1900 or 1904 date system) wherever the cell's number format is a date or time format. Formula cells give their last calculated result, error cells such as#N/AbecomeNULL, and fully empty rows are skipped and counted. Legacy.xlsfiles are not supported. - Type detection. Each column's non-empty values are tested against integer, decimal, boolean, date, timestamp and timestamp-with-offset patterns. If no pattern fits every value, the column is text. Numbers with leading zeros, like the ZIP code
02134, stay text so the zeros survive. A column of only1和0stays an integer, and impossible dates like2024-02-30don't count as dates. Integer columns becomeBIGINTonce a value passes 2,147,483,647, and decimal columns get a precision and scale that fit the longest value. You can override any column from the preview's header row. - Literals. Numbers and booleans are written unquoted, everything else as a quoted literal. Single quotes are doubled and MySQL also escapes backslashes. SQL Server strings get the
N'...'prefix so accented letters, CJK and emoji survive a non-Unicode database collation. Oracle dates useDATE '2024-03-08'和TIMESTAMP '...'literals, because a plain string fails under Oracle's default date format. Times are written as2024-03-08 10:15:00, which every engine accepts. A JSONnullalways becomes SQLNULL; an empty cell becomesNULLor an empty string depending on the option you picked and the column's type. - Identifiers and DDL. Table and column names are quoted per engine (
[brackets]对于 SQL Server,"double quotes"for PostgreSQL, SQLite and Oracle,`backticks`for MySQL), so names with spaces or reserved words survive. A table name likedbo.ordersis read as schema and table, and each part is quoted on its own. Names longer than the engine allows (128 characters in SQL Server, 63 bytes in PostgreSQL, 64 characters in MySQL, 128 bytes in Oracle 12.2 and later) get a warning. TheCREATE TABLEmaps each detected type to that engine's closest column type, and you can write it on its own, leave it out, or put it before the inserts. - Batching. You get one
INSERTper row by default. Turn on Multi-row VALUES under More options and every engine except Oracle folds rows into one statement per batch: 100 rows unless you change it, 1,000 at most, which is also the most SQL Server allows in oneVALUESlist. SQL Server output puts aGOafter theCREATE TABLEand after every 100INSERTstatements, so a long script runs as a handful of batches. - Large files. Inputs over 2 MB stop converting on every keystroke; press Convert or Ctrl+Enter (⌘+Enter on a Mac) instead. A file that large isn't copied into the paste box either: you see its first 200 lines. Any script longer than 500 lines shows only its first 500 in the SQL box, and Copy SQL and Download .sql always take the whole thing.
- 私密。 All of this happens in your tab. Nothing is uploaded, logged or stored, and the page keeps working offline once it has loaded.
Quoting differences per engine
The same data comes out as slightly different SQL for each database. Here is what the tool
writes for a column named order id and the value it's 5 o'clock.
| 引擎 | 标识符 | String literal | Backslash | 布尔值 |
|---|---|---|---|---|
| SQL Server | [order id] | N'it''s 5 o''clock' | ordinary character | 1 / 0 |
| PostgreSQL | "order id" | 'it''s 5 o''clock' | ordinary character | TRUE / FALSE |
| MySQL | `order id` | 'it''s 5 o''clock' | escaped as \\ | TRUE / FALSE |
| SQLite | "order id" | 'it''s 5 o''clock' | ordinary character | 1 / 0 |
| Oracle | "order id" | 'it''s 5 o''clock' | ordinary character | 1 / 0 |
Single-quoted literals with doubled quotes work everywhere. Identifiers, backslashes and date
literals are where pasted SQL breaks when you move it between databases. One more Oracle
quirk: an empty string 是 NULL there, so empty text cells arrive as
NULL whichever option you pick. The SQLly app handles the same differences while
you write; the per-database notes have the details.
Example: CSV in, PostgreSQL out
name,joined,score Ada,2023-01-15,91 Grace,2022-11-02,98 "Lee, Sam",2024-03-08,
CREATE TABLE "imported_data" (
"name" TEXT,
"joined" DATE,
"score" INTEGER
);
INSERT INTO "imported_data" ("name", "joined", "score") VALUES ('Ada', '2023-01-15', 91);
INSERT INTO "imported_data" ("name", "joined", "score") VALUES ('Grace', '2022-11-02', 98);
INSERT INTO "imported_data" ("name", "joined", "score") VALUES ('Lee, Sam', '2024-03-08', NULL);
The quoted third name keeps its comma. The dates are quoted literals because the column was
detected as a date, and the empty score becomes NULL because the column is an
integer. Pick MySQL and the same table comes out with backticks and an INT score
column. Pick Oracle and the dates are written as DATE '2023-01-15'.
CSV to SQL FAQ
Is the CSV to SQL converter free?
Yes. It's free to use with no sign-up and no usage limits, and it runs entirely in your browser tab.
Is my data uploaded anywhere?
No. JavaScript running in your tab parses the data and writes the SQL. Nothing is sent to a server, logged or stored, and once the page has loaded it keeps working offline.
Can I convert an Excel .xlsx file?
Yes. Open it with the file picker or drop it on the data side of the converter. The .xlsx is unpacked and read in your browser, never uploaded, and you pick the sheet when there are several. Text, numbers, TRUE/FALSE and date cells are read from their stored values, formulas give their last calculated result, and error cells become NULL. Legacy .xls and .ods files are not supported. Save them as .xlsx or CSV, or copy the range and paste it here.
How are empty cells handled: empty string or NULL?
You choose. By default an empty cell in a text column becomes an empty quoted string, and an empty cell in a numeric, boolean or date column becomes NULL, because an empty string isn't valid there. Tick Empty cells are NULL under More options to make every empty cell NULL. A JSON null always becomes NULL.
What column types does it detect?
Integer, decimal, boolean, date, timestamp, timestamp with a UTC offset, and text, worked out from the non-empty values in each column. Values with leading zeros stay text. You can override the guess per column with the dropdowns in the preview table's header row, and both the CREATE TABLE and the literals follow your choice.
Why is the quoting different for each database?
Each engine spells identifiers and string escapes its own way. SQL Server wraps names in [brackets], PostgreSQL, SQLite and Oracle use "double quotes", and MySQL uses `backticks`. String literals take single quotes everywhere, but MySQL also escapes backslashes, SQL Server needs the N prefix for Unicode text, and Oracle needs DATE and TIMESTAMP literals. The tool applies the rules of the engine you picked.
What is the multi-row VALUES option?
It folds rows into one INSERT with a long VALUES list instead of writing one INSERT per row, which cuts round trips and parse work on import. It's 100 rows per INSERT unless you change Rows per INSERT under More options, up to 1,000. PostgreSQL, MySQL, SQLite and SQL Server all support it; SQL Server caps one VALUES list at 1,000 rows. Oracle only accepts multi-row VALUES from 23ai, so Oracle output stays one INSERT per row.
Does it escape quotes and special characters in my data?
Yes. Embedded single quotes are doubled, MySQL also escapes backslashes, and quoted CSV fields that contain commas, quotes or newlines survive parsing intact because the parser follows RFC 4180. A line break inside a value stays a real line break inside the quoted literal. If you run Oracle output in SQL*Plus, put SET DEFINE OFF first so an & in your data isn't read as a substitution variable, and SET SQLBLANKLINES ON if a value contains an empty line.
Like the converter? Meet the rest of SQLly
A native SQL workbench for macOS, Windows and Linux, with IntelliSense that knows your schema, guardrails for risky queries, and fast result grids you can paste straight back into a spreadsheet.