Format Code Now
/
ConvertSQL INSERT to CSV Next: SQL INSERT to JSON ›

SQL INSERT to CSV Converter

CV-106

Paste INSERT ... VALUES statements and get a CSV with the column names as the header. Quoted strings, NULL and large numbers are read exactly.

Runs in your browser. Nothing is uploaded.

SQL INSERT statements (optional first line: -- table: name)

CSV

How to use it

  1. Paste your SQL INSERT statements.
  2. Pick the string escape style: Standard, or MySQL for backslash escapes.
  3. Choose the delimiter and how NULL should appear.
  4. Press SQL to CSV, then copy or download.

What it reads

The tool reads INSERT ... VALUES statements, including multi-row inserts and column lists written with [brackets], "double quotes" or `backticks`. Every other statement, such as CREATE TABLE, UPDATE or SET, is skipped. INSERT ... SELECT is an error, because the rows do not exist in the text. Without a column list the columns are named column_1, column_2 and so on. A value that is a function or expression, such as NOW(), is kept as its text, since nothing is evaluated.

Strings, NULL and numbers

Text is written without its SQL quotes, with doubled quotes turned back into one. In the MySQL setting, backslash escapes such as \n are decoded too. NULL becomes an empty cell or the text NULL, so a true empty string and NULL look alike by default. Numbers and TRUE or FALSE are copied as written, so a 19-digit number is not rounded. CSV holds one table, so if the SQL inserts into several, put -- table: name on the first line.

Error messages and what to do

MessageWhat it meansFix
No INSERT ... VALUES statements foundThe text has no INSERT with a VALUES list.Paste INSERT INTO ... VALUES (...) statements.
The SQL inserts into more than one table (a, b). Put -- table: name on the first line to choose one.CSV can hold only one table.Add a -- table: line naming the table you want.

Questions people ask

How do I convert SQL INSERT statements to CSV?

Paste the statements and press SQL to CSV. The column list becomes the header and each row in VALUES becomes a CSV line. Copy the output or download it as a .csv file.

Can it read a mysqldump file?

Yes for the INSERT lines. Switch String escapes to MySQL so backslash sequences in strings are decoded. Other statements in the dump, such as CREATE TABLE and LOCK TABLES, are skipped.

What if the dump has many tables?

CSV holds one table. Put -- table: customers on the first line to pick one. The part after the last dot also matches, so customers finds dbo.customers.

Are big numbers rounded?

No. Numbers are copied digit for digit from the SQL text and never pass through a floating-point value, so long IDs and precise decimals stay intact in the CSV.

Does it run my SQL?

No. The text is only read, never executed, and no database is involved. Functions like NOW() are not evaluated; they come through as their text.

About this tool

Only INSERT ... VALUES statements are read, including multi-row inserts and the quoted-name styles of SQL Server, PostgreSQL and MySQL. Every other statement (CREATE TABLE, UPDATE, SET and so on) is skipped, and INSERT ... SELECT is an error. Without a column list the columns are named column_1, column_2 and so on. Numbers are kept digit for digit, so a 19-digit ID is not rounded. A value that is a function or expression, such as NOW() or CURRENT_TIMESTAMP, is kept as its text, since nothing is evaluated. CSV can hold only one table: if the SQL inserts into several, put -- table: name on the first line to choose (the part after the last dot also matches). Text is written without its SQL quotes, true and false as typed, and NULL as an empty cell or the text NULL, so a real empty string and NULL look the same by default. The MySQL option reads backslash escapes such as \n and \' inside strings; leave it on Standard for SQL Server, PostgreSQL and SQLite dumps. The apostrophe option changes cells that start with = + - or @ and is off by default.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.