Skip to content

CSV to SQL Converter

Generate CREATE TABLE and INSERT statements from a CSV file, quoted correctly for your database.

Processed in your browser. Your data is not uploaded, stored or logged — closing the tab discards it. How this works

SQL options Show
Statements
Values

Changes apply automatically.

CSV input

Paste CSV, choose a file, or load the sample customer list.

You can also drag and drop a file here.

SQL output

The SQL statements appear here.

Columns

Name and SQL type of each column

Column types appear here.

Parsed rows

The parsed rows appear here after conversion.

How to convert CSV to SQL

  1. Paste CSV or open a file. Check the parsed rows and the column list.
  2. Choose your database and enter the table name.
  3. Decide whether to include CREATE TABLE, whether empty values should be NULL, and whether to detect numeric columns.
  4. Copy the SQL into your database client, or download it as a .sql file and run it.

Example

For PostgreSQL with numeric detection on, this CSV:

id,name,price
1,O'Brien,9.50
2,Ana,

becomes:

CREATE TABLE "my_table" (
  "id" BIGINT,
  "name" TEXT,
  "price" DECIMAL(3, 2)
);

INSERT INTO "my_table" ("id", "name", "price") VALUES
  (1, 'O''Brien', 9.50),
  (2, 'Ana', NULL);

What changes between dialects

PostgreSQLMySQLSQLiteSQL Server
Identifier quotes"name"`name`"name"[name]
Text typeTEXTTEXTTEXTNVARCHAR(MAX)
Integer / decimalBIGINT / DECIMAL(p, s)BIGINT / DECIMAL(p, s)INTEGER / NUMERICBIGINT / DECIMAL(p, s)
String escaping'''' and \\'''', N'…'
Max rows per INSERTNo fixed limitLimited by packet sizeNo fixed limit1,000

Decimal precision and scale are calculated from the longest values in the column, so the type fits every value exactly.

Limitations

  • Dates and booleans are inserted as text. Cast them in SQL afterwards, or alter the column type, if you need native types.
  • No primary keys, indexes or constraints are created; add those to suit your schema.
  • Completely empty rows are skipped. Rows with missing fields get NULL (or an empty string) for the missing values.
  • Maximum input size is 50 MB. For larger imports, use your database's bulk loader.

Frequently asked questions

Which databases does the SQL work with?

PostgreSQL, MySQL and MariaDB, SQLite and Microsoft SQL Server. The dialect setting changes how table and column names are quoted, how strings are escaped, the column types, and the transaction keywords.

Why are all my values in quotes?

By default every column is TEXT and every value is a string literal, which never changes your data. Turn on "Detect numeric columns" to create INTEGER or DECIMAL columns — a column only becomes numeric if every value in it is a plain number, so ZIP codes and IDs with leading zeros stay text.

How are apostrophes and special characters handled?

Single quotes are doubled (O'Brien becomes 'O''Brien'), which is standard SQL. For MySQL, backslashes are also escaped because MySQL treats them as escape characters by default. For SQL Server, strings use the N'…' prefix so Unicode text is stored correctly. Table and column names are quoted with the dialect's identifier quotes.

Should I use INSERT statements for large files?

For a few thousand rows, INSERT statements are convenient. For very large imports, the database's bulk loader is faster: COPY in PostgreSQL, LOAD DATA INFILE in MySQL, .import in SQLite, or BULK INSERT in SQL Server. Those read the CSV file directly.

Is it safe to run the generated SQL?

Values are escaped as literals, so data cannot break out of a string. Still, review the CREATE and DROP statements before running them, and test on a copy of your database first — especially with "Drop table first" enabled.

Last updated .