CSV to SQL

Generate CREATE TABLE and INSERT statements from CSV.

The CSV to SQL converter turns CSV data into an optional CREATE TABLE statement plus INSERT statements for MySQL, PostgreSQL or SQLite. It can detect the delimiter, use the first row as column names and infer column types from the values. Use it to import spreadsheet exports into a database without writing the SQL by hand.

From CSV rows to SQL statements

CSV is a plain-text table: each line is a row and the values on a line are separated by a delimiter, usually a comma. Quoted values can contain the delimiter or line breaks. SQL databases need typed columns and quoted values, so the converter parses the CSV, treats the first row as column names (if you leave First row is header ticked) and decides a type for each column from its values. Whole numbers become integers, decimals become floating-point, true and false become booleans, and everything else becomes text. Empty cells become NULL. Values that look like numbers but have a leading zero, such as the postal code 02134, are kept as text so the zero is not lost. The Dialect option sets type names, identifier quoting and boolean literals.

How to use CSV to SQL

  1. Provide the CSV Paste CSV into the CSV box or load a file with the file button.
  2. Set parsing options Choose a Delimiter (Auto by default) and tick or untick First row is header.
  3. Set the SQL options Enter a Table name, pick a Dialect, set Rows per INSERT and tick or untick Include CREATE TABLE.
  4. Copy or download Copy the SQL from the SQL box or download it as output.sql.

Frequently asked questions

How does Auto delimiter detection work?

The CSV parser looks at the text and guesses the delimiter. If the guess is wrong for your data, choose Comma, Semicolon, Tab or Pipe explicitly.

How are empty cells handled?

An empty cell becomes NULL in the INSERT statement.

How are column types chosen?

From all values in the column: whole numbers are integers (BIGINT when beyond the 32-bit range), decimals are floating-point, true and false are booleans, and anything else is text. A column mixing these becomes text or, for numbers only, floating-point.

Can I import TSV files?

Yes. Load a .tsv file, or paste tab-separated text and choose Tab (or leave Auto) as the delimiter.

Does it add a primary key?

No. Only the columns from your CSV are created, with no keys or constraints. Add them to the CREATE TABLE as needed.

Is my CSV sent to a server?

No. Files and pasted text are read and converted in the page and are not sent anywhere.