Convert

CSV to SQL

Turn a CSV file into a CREATE TABLE statement with sensible column types plus batched INSERT statements, with identifiers and strings quoted the way your database expects.

CSV data

No data yet.

Parsing options

Options

Database

Add a CSV file to get started.

SQL

How to convert CSV to SQL

  1. Paste CSV or open a file, then pick your database.
  2. Name the table (use schema.table to qualify it) and choose how many rows go into each INSERT.
  3. Check the inferred column types in the list above the SQL, then copy the script or download it as a .sql file.

What each option does

CREATE / DROP / IF NOT EXISTS
Controls the table statements. SQL Server has no CREATE TABLE IF NOT EXISTS, so an IF OBJECT_ID(…) IS NULL check is written instead; DROP TABLE IF EXISTS needs SQL Server 2016 or later.
Infer column types
Scans every value. Untick it to load everything as text and convert later in SQL.
Empty cells become NULL
Otherwise empty text stays an empty string. Empty cells in number, date and boolean columns are always NULL.
Transaction
Wraps the INSERTs in BEGIN and COMMIT, which is much faster on SQLite and gives all-or-nothing loading everywhere.
snake_case names
Turns "Order Date" into order_date so you never need to quote it in queries.

Text columns are sized from the longest value: VARCHAR in MySQL, NVARCHAR in SQL Server (with N'…' literals so any language survives), TEXT in PostgreSQL and SQLite.

Frequently asked questions

How are column types chosen?

Each column is scanned in full. Whole numbers become INT or BIGINT (DECIMAL beyond 64 bits), other numbers DECIMAL with enough precision, true/false BOOLEAN (BIT in SQL Server, 0/1 in SQLite), ISO dates and timestamps DATE and TIMESTAMP types, and everything else text. Values with leading zeros, such as ZIP codes, stay text.

How are quotes and special characters escaped?

Single quotes are doubled in every dialect. MySQL also treats the backslash as an escape character, so backslashes are doubled there. Identifiers are quoted with backticks (MySQL), double quotes (PostgreSQL, SQLite) or square brackets (SQL Server), so names with spaces or reserved words work.

What batch size should I use?

100 to 1,000 rows per INSERT suits most databases. SQL Server accepts at most 1,000 rows in one INSERT … VALUES statement, so larger batches are capped. A batch size of 1 writes one statement per row, which is easiest to debug.

My MySQL server uses NO_BACKSLASH_ESCAPES. What changes?

In that mode a backslash is an ordinary character, so doubling it would store two. Untick "Escape backslashes (MySQL)" and only single quotes are doubled.