CSV to SQL

Convert CSV to SQL instantly in your browser.

Local Your input is processed locally in your browser. Found a problem? Report an issue

What CSV to SQL does

CSV to SQL reads CSV and writes it as SQL. The input is parsed first, so a syntax error is reported with its position instead of producing broken output.

CSV is a plain-text table: one row per line, values separated by commas. Every spreadsheet opens it. SQL INSERT statements add rows to a database table. Running them in MySQL, PostgreSQL, SQLite or SQL Server loads the data.

CSV to SQL example

Input

id,name,city
1,Ada,London
2,Lin,Bengaluru

Output

-- Table name: data. Rename it to match your database.
INSERT INTO data ("id", "name", "city") VALUES (1, 'Ada', 'London');
INSERT INTO data ("id", "name", "city") VALUES (2, 'Lin', 'Bengaluru');

The output is what this tool produces for the input above it.

How it works

Reading CSV. The first line is the header. Quoted values may contain commas, quotes and line breaks.

Writing SQL. Each record becomes one INSERT INTO data (...) VALUES (...); statement. Column names are the keys of the records, with nested objects flattened into dotted names and quoted as identifiers. Text is put in single quotes with any single quote doubled, numbers are written as numbers, true and false become TRUE and FALSE, and missing values become NULL.

Details and limits

  • Everything runs on your device, so there is no upload and no fixed size limit; very large inputs depend on its memory.
  • It works in current browsers on phones, tablets and computers, and it is free with no account.
  • The table is named data. Change the name, and add a CREATE TABLE statement if the table does not exist yet.
  • Numbers are detected only when the whole value is a plain number such as 42 or 3.5.

Questions

Is my data uploaded?

No. The conversion runs in your browser.

Is CSV to SQL free?

Yes, with no sign-up and no limit on use.

Which databases accept the output?

MySQL, MariaDB, PostgreSQL, SQLite and SQL Server all accept these INSERT statements. Column names are in double quotes, the SQL standard; in MySQL, turn on ANSI_QUOTES or replace them with backticks.

Can I convert SQL back to CSV?

Not with this tool. To get rows out of a database, export the query result as CSV or JSON from your database client.