CSV to SQL
A pasted table, ready to run.
Examples temporarily replace the input and settings. You can restore your previous work.
Paste or type above to see the result here.
Your files stay on your device
This tool runs entirely in your browser. What you paste is processed on your device and is never sent to a server, so it is safe to use with tokens, keys and unpublished text.
Example
Example: three web-shop orders from a spreadsheet, as CREATE TABLE and INSERT
A small online shop keeps its orders in a spreadsheet and is moving them into a database. The sheet is exported as CSV with its header row, Order ID, Customer, Order date, Total (£), Gift wrap and Delivery note, and pasted in. Table name orders; separator worked out; first row as column names; CREATE TABLE on; no quotes; 100 rows per INSERT.
- The headings become names any database accepts: lower case, symbols and spaces turned into underscores, so “Total (£)” becomes total and “Order date” order_date.
- Each column gets the narrowest type all its values fit: whole numbers INTEGER, 24.50 DECIMAL(18,6), TRUE and FALSE BOOLEAN, 2026-03-14 DATE, text VARCHAR rounded up to 16 or 32.
- Values are written as literals: Sarah O'Neill becomes 'Sarah O''Neill' with the quote doubled, and James Patel’s empty delivery note becomes NULL.
- All three rows go into one INSERT, since up to 100 share a statement.
| Column | Values | Type |
|---|---|---|
| order_id | 1041, 1042, 1043 | INTEGER |
| customer | Sarah O'Neill, James Patel, Megan Hughes | VARCHAR(16) |
| order_date | 2026-03-14, 2026-03-15 | DATE |
| total | 24.50, 8.99, 112.00 | DECIMAL(18,6) |
| gift_wrap | TRUE, FALSE | BOOLEAN |
| delivery_note | Two notes and one empty cell | VARCHAR(32) |
One CREATE TABLE orders and one INSERT whose second row reads (1042, 'James Patel', '2026-03-14', 8.99, FALSE, NULL). Had the dates been typed the British way, 14/03/2026, the column would have come out VARCHAR(16): format them as yyyy-mm-dd first to get DATE.
How it works
- Paste the CSV or TSV — straight out of a spreadsheet works.
- Name the table. Quote the identifiers if your database needs it.
- Leave CREATE TABLE on for a new table; turn it off to insert into one you already have.
- Copy the SQL and run it. Read it first.
Frequently asked questions
- How does it choose the column types?
- The tool checks every non-empty cell in a column. A ZIP code such as 02139 keeps the column as text so the leading zero survives. Whole numbers use INTEGER or, for larger values, BIGINT or DECIMAL. For decimals, the precision and scale grow to fit the sample. If that would require more than 38 digits of precision, the column becomes text. Valid ISO dates such as 2024-02-29 become DATE. Mixed dates and free text stay text.
- Are the values escaped?
- A quote inside a value is doubled, which is the escape every dialect agrees on, and an empty cell becomes NULL rather than an empty string. That is right for a file you are about to run yourself against your own data.
- Can I use this on data from a form or an API?
- Not safely. These are literals, not placeholders, so building statements this way from input you did not type is how SQL injection happens. For anything automated, use your driver’s parameters.
- Why does it batch the rows?
- One INSERT with a hundred rows runs far faster than a hundred INSERTs, and stays small enough to read. Drop it to one per statement if you need to run them individually.
- Why are my dates VARCHAR and not DATE?
- Only dates written year first, such as 2026-03-14, become DATE (and 2026-03-14 09:30 becomes TIMESTAMP). 14/03/2026 or 03/14/2026 is not read as a date at all, so the column stays text rather than risk swapping day and month. Format the date column as yyyy-mm-dd in the spreadsheet before you copy it.
- What happens to headings with spaces or symbols?
- They are made safe for any database: lower case, each run of spaces or symbols turned into one underscore, and c_ put in front of a name that starts with a digit. “Total (£)” becomes total, “Order date” order_date and “2026 sales” c_2026_sales; an empty heading becomes column_1, column_2 and so on.
- Is anything sent to a server?
- No. It runs in your browser, so what you paste stays on your computer.