Clever Quest Lab Tools

CSV to SQL Converter

2026-10-17

Paste CSV and get SQL INSERT statements with your table name, delimiter, NULL rule and batch size, or paste INSERT statements and get a table and CSV back. Quoted fields, embedded line breaks, escaped quotes and guessed column types are handled. Everything runs in your browser.

CSV to SQL INSERT

A dot makes a schema, for example public.people.
1 = one statement per row.

    SQL INSERT to table and CSV

      Your data stays in this browser tab — nothing is uploaded or sent to a server.

      How to use the CSV to SQL converter

      1. Paste your CSV into the first box, or press Open CSV file. The SQL appears as you type.
      2. Type the table name. A name with a dot, such as public.people, is split into schema and table.
      3. Leave the delimiter on Auto-detect, or pick comma, semicolon, tab or pipe.
      4. Choose how identifiers are quoted: "name" (standard SQL), `name` (MySQL style) or [name] (SQL Server style).
      5. Decide what empty fields become (NULL or an empty string), how many rows go into one INSERT, and whether to add a CREATE TABLE statement with guessed types.
      6. Press Copy SQL or Download .sql. To go the other way, paste INSERT statements into the second box and copy or download the CSV.

      How it works

      The CSV reader follows the rules of RFC 4180. A field that contains the delimiter, a double quote or a line break must be wrapped in double quotes, and a quote inside a quoted field is written twice. Lines may end in LF, CRLF or CR. A byte order mark at the start is ignored and completely empty lines are skipped. A quote in the middle of an unquoted field is kept as text.

      Each value is then turned into an SQL literal. Text goes in single quotes and every single quote is doubled, which is the standard way to escape it. In MySQL style a backslash is doubled as well, because MySQL treats it as an escape character by default. In SQL Server style, text with non-ASCII characters gets the N prefix so that it stays Unicode.

      A column is written without quotes only when every non-NULL value in it is a plain number: an optional minus sign, digits without leading zeros, an optional fraction and an optional exponent. Values such as 007, +5 or 1,5 stay text. Numbers are never converted to floating point, so long values keep every digit.

      The guessed type of a column comes from the same values: whole numbers become INTEGER (or BIGINT when they do not fit 32 bits), numbers with decimals become DECIMAL(p,s) with the digits actually seen, exponents give a floating-point type, valid YYYY-MM-DD dates become DATE, dates with a time become a timestamp, and anything else becomes VARCHAR sized to the next of 16, 32, 64, 128 or 255 characters, or TEXT above that. It is a starting point, so check it before you run it.

      The reverse direction reads INSERT INTO t (a, b) VALUES (...), (...); statements. It understands '' and \' inside strings, NULL, numbers, comments and quoted names, and it merges several statements for the same table. Other statements are skipped, and an expression such as NOW() is copied as text.

      Examples

      1. The default example. Four rows with a quoted comma, a quoted quote and an empty score. With table people, standard quotes and NULL for empty values, one statement is produced:

      INSERT INTO "people" ("id", "name", "city", "score", "joined") VALUES
        (1, 'Ada Lovelace', 'London', 92.5, '2024-01-15'),
        (2, 'O''Brien, Pat', 'Dublin', NULL, '2024-02-03'),
        (3, 'Grace "Amazing" Hopper', 'New York', 88, '2024-03-21'),
        (4, 'Linus', 'Helsinki', 75.25, NULL);

      With Add CREATE TABLE switched on, the columns are guessed as INTEGER, VARCHAR(32), VARCHAR(16), DECIMAL(4,2) and DATE.

      2. Semicolons and leading zeros. The input code;label;qty, then 007;Widget;5, then 12;"Nut; M4"; is detected as semicolon-separated. With table parts you get:

      INSERT INTO "parts" ("code", "label", "qty") VALUES
        ('007', 'Widget', 5),
        ('12', 'Nut; M4', NULL);

      The code column stays quoted because 007 is not a plain number, while qty is numeric once the empty value is NULL.

      3. MySQL style, one row per statement. For id,path with the rows 1,C:\temp and 2,O'Neil, table files, MySQL quotes and one row per INSERT:

      INSERT INTO `files` (`id`, `path`) VALUES (1, 'C:\\temp');
      INSERT INTO `files` (`id`, `path`) VALUES (2, 'O''Neil');

      4. INSERT to CSV. The statement INSERT INTO t (a, b) VALUES (1, 'x, y'), (2, NULL); gives a table with two rows and this CSV, where the comma forces quotes and NULL is an empty field:

      a,b
      1,"x, y"
      2,

      Why some numbers stay in quotes

      CSV has no types, so the converter has to decide. Zip codes, phone numbers, product codes and account numbers often start with a zero or carry a plus sign. Written as numbers, 007 would be stored as 7 and the zero would be lost. Quoting the whole column is the safe choice, and databases convert quoted digits to a numeric column on insert. If you want every value quoted, switch off Leave numbers unquoted.

      Differences between databases

      Frequently asked questions

      Does the converter handle line breaks inside a field?

      Yes, if the field is in double quotes. The line break is kept inside the SQL string literal.

      What is the difference between an empty value and NULL?

      CSV cannot tell them apart. NULL means unknown and an empty string is a known empty text, so pick the one your column expects. NOT NULL text columns usually need the empty string.

      My first row is data, not a header. What do I do?

      Untick First row is a header. The columns are then named col1, col2 and so on, and every row becomes data.

      What happens when rows have different numbers of fields?

      Short rows are filled with NULL, extra fields become new columns named column_N, and the page tells you how many rows were affected.

      Is this safe to run on the generated SQL?

      Quotes are escaped, but always read the statements and test them on a copy of the table first. This tool does not connect to any database.

      Is my data uploaded anywhere?

      No. Parsing, conversion and file reading all happen in your browser. Nothing is sent to a server, and the text you type is only kept in your own browser storage so it is there when you return.

      Related tools