CSV to SQL

Turn CSV rows into CREATE TABLE and INSERT statements for MySQL, PostgreSQL, SQLite or SQL Server.

Add CSV and click Convert to see the SQL here.

How CSV to SQL works

Turns CSV rows into SQL INSERT statements, with a CREATE TABLE statement at the top if you want one. The header row gives the column names. Choose your database: MySQL, PostgreSQL, SQLite or SQL Server.

Names and values are quoted and escaped for the database you pick, so quotes in your data do not break the SQL. Column types in CREATE TABLE are guessed from your data, like INT, DOUBLE, BOOLEAN or VARCHAR(255).

Input to CSV to SQL

  • Paste or type CSV into the input box, or upload or drop a .csv or .txt file. The separator is found for you.
  • Table sets the table name. Add a schema with a dot, like shop.orders. Rows per INSERT can be 1, 100, 500 or 1000.
  • Add CREATE TABLE puts a table definition before the inserts. Read numbers and true/false writes 42 and true as a number and a boolean instead of text.
  • Turn off "First row is the header" when your data has no header. Columns are then named Column 1, Column 2 and so on.

Output from CSV to SQL

  • SQL with syntax highlighting. Empty cells become NULL.
  • Names are quoted with backticks for MySQL, square brackets for SQL Server and double quotes for PostgreSQL and SQLite.
  • Empty or repeated column names get unique names, like column_3 or name_2.
  • Copy it, download it as output.sql or open it in full screen. Change an option and the SQL updates right away.