araç köşesi

CSV to SQL INSERT

Turn a CSV table into INSERT statements you can run: quotes escaped, empty cells written as NULL

Your data stays with you. Conversion happens inside the browser; nothing is sent to a server.

How it works

Paste your CSV table into the left box; the INSERT statements build up in the right box as you type. The first line is treated as the header and its cells become the column list: a 120-row customer export turns into 120 INSERT statements the moment you paste it. Column names are adapted for SQL — a heading like 'order date' becomes 'order_date', because a space inside an unquoted identifier breaks the statement — and the status line tells you how many names changed. The rules for values are fixed: text is wrapped in single quotes, a single quote inside the text is doubled ('O''Brien'), empty cells become NULL and numbers are written without quotes. Quoted CSV fields are parsed properly, so a cell containing a comma or a line break stays one cell as long as you wrapped it in double quotation marks. With the delimiter on automatic, several rows are weighed instead of the first one alone: the candidate that yields the same number of columns on every row wins. All three line endings are read as well — the CR+LF of Windows, the LF of macOS and Linux, and the lone CR of much older programs, which many tools mistake for a single long line. If a row carries more cells than the header, the conversion stops and names the data row and the cell count — in practice that is almost always an unquoted separator. Copy the output or download it as an .sql file and run it in your database client.

This tool is also known as csv to sql, csv to sql insert, generate insert statements from csv, convert spreadsheet to sql, csv to insert into.

What is INSERT statement?

INSERT is the SQL command that adds a new row to a table, and it has three parts: which table to write to, which columns to fill and the values. INSERT INTO customer (name, city) VALUES ('Anna', 'Bristol') shows all three. The column list is optional in SQL, but writing it should be a habit: without it, values are matched to the table's column order, so the day somebody adds a column the old statements quietly start writing into the wrong field. This tool always writes the column list, which also means the statements survive schema changes that only add columns.

What is NULL?

NULL is SQL's marker for 'no value', and it is neither zero nor an empty string. The distinction shows up in comparisons: nothing equals NULL, not even NULL itself, which is why you search for blanks with IS NULL rather than an equals sign; most aggregate functions also skip NULL rows instead of counting them as zero. A blank cell in a CSV export usually means the information was never supplied, so this tool writes NULL rather than a quoted empty string — the two behave differently in every later query you write against the table.

What is Escaping a single quote?

Escaping means writing a character that has special meaning in its context so the system reads it as data rather than syntax. In SQL that character is the single quote, because it delimits text values: every single quote inside a value must be written twice. This is the standard mechanism and behaves the same in MySQL, PostgreSQL, SQLite and SQL Server. Backslash escaping is an additional MySQL behaviour and is not portable. When escaping is forgotten the symptom is familiar — every row containing an apostrophe either errors out or lands in the table truncated at that character.

What is the difference between one INSERT per row and a single bulk INSERT?

Both write the same rows into the same table; they differ in speed and in what happens when something is wrong. With one statement per row the database parses each statement separately, which is measurably slower across tens of thousands of rows — but a row with a type mismatch or a duplicate key fails alone, the rest are written, and the failing row is easy to identify from the error. With a single INSERT carrying many VALUES the parsing happens once and there is a single round trip to the server, which makes bulk loading several times faster. The price is that the statement is one unit: a single malformed row can cause the whole batch to be rejected, and finding it means reading through the values by hand. The practical rule is to load data you have not verified row by row, and to load data you trust in one statement.

Why single quotes are doubled

SQL wraps text values in single quotes. When the value itself contains one — O'Brien, l'hôtel, 'Ali'nin' — the database reads that mark as the end of the string and tries to parse the rest as commands. The result is either a syntax error or, worse, a row stored with half its content.

The standard fix is doubling: every single quote inside the value is written twice, and the database reads it back as one character. This tool applies that to every value. Doubling is not the same as backslash escaping, and it is preferred for a concrete reason — backslash escaping is a MySQL default rather than a standard, while doubling behaves identically in every engine.

What differs between MySQL, PostgreSQL and SQLite

The generated SQL is deliberately plain so that it runs on all three. The differences worth checking before you execute it are these:

  • Dates and times are written as text. PostgreSQL will not silently accept 03/04/2026; depending on the column type you may need an explicit conversion, and the day-first or month-first reading is ambiguous anyway
  • Backslashes: MySQL treats a backslash as an escape character by default, PostgreSQL and SQLite do not. If your data contains file paths, test the output on MySQL first
  • Identifier quoting differs — backticks in MySQL, double quotes in PostgreSQL and SQLite. Names here are reduced to ASCII letters, digits and underscores, so the output needs no quoting at all and runs everywhere
  • Booleans are quoted as text. SQLite has no boolean type and MySQL expects 1/0, so convert them after loading if the column is not text
  • Decimals: 1250.50 is written as a bare number; 1.234 and 1,250.50 stay quoted text, because exactly three digits after the mark may be a thousands group as easily as a fraction — a guess here moves the amount by a factor of a thousand

Which setting for which job?

All five settings depend on where the statements will run; the defaults cover the most common case.

  • A few hundred rows into a test database → one INSERT per row (if one row fails, the rest still land)
  • Tens of thousands of rows into production → single INSERT with many VALUES, noticeably faster
  • Every column is VARCHAR or TEXT → quote everything
  • Phone numbers, postcodes, national ID columns → the tool already quotes these (a leading zero or more than 15 digits keeps the cell as text); if the whole column is VARCHAR anyway, quote everything is still the clearer choice
  • Data copied out of Excel → set the separator to semicolon or tab; override the automatic detection when it guesses wrong
  • Export without a header → choose 'no column names'; columns are called c1, c2 and you rename them in the output

This tool does not write CREATE TABLE

The output is INSERT statements only; the table is assumed to exist already. That is an honesty decision. Guessing column types from a CSV file is risky: a column of digits looks numeric but may be a postcode, a 12-digit field can overflow an integer, and two date rows can be followed by a third holding free text.

A wrongly guessed type produces a table that looks right while quietly losing data — stripped leading zeros are the classic case. If you create the table yourself, you decide every column type knowingly, and this tool moves the rows into it with the escaping done properly.

Frequently asked questions

How do I generate SQL INSERT statements from a CSV file?

Paste the CSV table into the left box and type the target table name; the INSERT statements appear immediately in the right box. Copy them or download an .sql file and run it in your database client. The table itself has to exist beforehand.

Do names with apostrophes break the statements?

No. A single quote inside a value — O'Brien, l'hôtel — is doubled the way the SQL standard requires, and the database reads it back as one character. Without doubling, the statement would end at that apostrophe and either fail or store a truncated value.

Does an empty cell become NULL or an empty string?

It becomes NULL, because a blank cell in a CSV export almost always means 'no value was supplied'. If your data genuinely needs empty strings, load the rows first and run a targeted update on that column afterwards.

Are date columns transferred correctly?

Dates are quoted as plain text exactly as they appear. If the target column is a date type, the format has to be one the database accepts: ISO notation (2026-08-24) is read correctly by all three engines, while 24/08/2026 usually needs conversion.

Is the table I paste sent to a server?

No. Parsing and SQL generation run entirely inside your browser, so customer lists, price exports and staff records stay on your machine. Nothing is uploaded, logged or stored.