ModernCalcs

SQL to CSV Converter

id,name,price,in_stock
1,Widget A,9.99,true
2,Gadget B,24.95,true
3,Doohickey C,4.50,false
4,Thingamajig D,,true

Column names from the INSERT statement become CSV headers. NULL becomes empty string. TRUE/FALSE become lowercase literals. Fields with commas are quoted.

SQL to CSV: Convert Database Row Data for Spreadsheets and Analysis

SQL INSERT statements from database dumps contain the same data you'd find in a spreadsheet — but in a format that Excel, Google Sheets, and BI tools can't directly open. This converter extracts column names and row values from an INSERT INTO statement and outputs properly formatted CSV with a header row, ready to import anywhere.

Formula
INSERT INTO products (id, name, price) VALUES (1, 'Widget A', 9.99), (2, 'Gadget B, Pro', 24.95), (3, 'Item C', NULL); → CSV: id,name,price 1,Widget A,9.99 2,"Gadget B, Pro",24.95 3,Item C,

Column names from INSERT become the CSV header. NULL → empty field. Values with commas are wrapped in double quotes.

SQL Dump to Spreadsheet Workflow

Database administrators export data with tools like mysqldump, pg_dump, or SQL Server's BCP. The output contains INSERT statements that are not directly readable by spreadsheet tools. Converting to CSV lets you open the data in Excel, Google Sheets, or load it into data analysis tools like pandas, R, or Tableau.

How Column Headers Are Extracted

The column list in INSERT INTO table (col1, col2, col3) becomes the CSV header row. Column names with backtick, bracket, or double-quote delimiters (MySQL, SQL Server, PostgreSQL respectively) are stripped to plain identifiers. The column order in the INSERT statement determines the column order in the CSV.

Value Conversion Rules

NULL → empty CSV field (the empty string between two commas). TRUE/FALSE → lowercase true/false. Numbers stay unquoted. Single-quoted SQL strings become unquoted CSV values (or quoted if they contain commas). The SQL single-quote escape '' is converted back to a single '.

Practical Examples

Opening a Database Dump in Excel

Convert an INSERT statement from a SQL dump file to open in Excel.

  • 1.Find the INSERT statement in your .sql dump file
  • 2.Copy the INSERT (can be multi-row)
  • 3.Paste and copy the CSV output
  • 4.Paste into Excel or save as .csv and open with File → Open

What This Converts

  • INSERT INTO column list → CSV header row
  • Each value tuple → one CSV row
  • NULL → empty field
  • TRUE/FALSE → lowercase literals
  • Strings with commas → double-quoted CSV fields
  • Multiple value rows → multiple CSV lines

Frequently Asked Questions

What SQL INSERT syntax is supported?

The converter supports INSERT INTO table_name (col1, col2, ...) VALUES (val1, val2, ...), (...) syntax. Column names are extracted from the column list and become the CSV header row. Multiple value tuples in a single INSERT all become rows in the CSV output.

How is NULL handled in CSV?

SQL NULL is converted to an empty field in the CSV output. A row like (1, NULL, 'Alice') becomes 1,,Alice in CSV. This is the conventional way to represent missing values in CSV, and most spreadsheet and import tools treat an empty field as a null or missing value.

How are TRUE and FALSE handled?

SQL TRUE and FALSE (case-insensitive) are written as the lowercase strings true and false in the CSV. They are not quoted since they don't contain commas or special characters.

Can I import the CSV into Excel or Google Sheets?

Yes. The CSV output follows RFC 4180 — fields with commas are double-quoted, embedded quotes are escaped as "". Excel and Google Sheets both import this format correctly. Use File → Import in Google Sheets or open the .csv file directly in Excel.