Convert CSV to SQL

CSV rows to INSERT statements.

Database
Separator

0 lines · 0 characters

0 lines · 0 characters

Results update as you type.

Runs in your browser. Nothing uploaded.

How to convert CSV to SQL

  1. Paste your CSV, open a .csv file or drop one onto the box. Data copied from Excel or Google Sheets works too (it arrives tab-separated).
  2. Type the Table name, pick your Database and how many rows go in each INSERT.
  3. Check the column types in the CREATE TABLE, then copy the SQL or download it as a .sql file and run it in your database.

What each database gets

The same CSV produces slightly different SQL for each database, because they don’t agree on types or quoting:

MySQL PostgreSQL SQLite SQL Server
Names quoted with `name` “name” “name” [name]
Text column VARCHAR(n) or TEXT TEXT TEXT NVARCHAR(n)
Decimal DECIMAL(p, s) NUMERIC(p, s) NUMERIC DECIMAL(p, s)
true / false BOOLEAN, TRUE BOOLEAN, TRUE INTEGER, 1 BIT, 1
Date DATE DATE TEXT DATE
Date and time DATETIME TIMESTAMP TEXT DATETIME2

VARCHAR lengths leave some room above the longest value (50, 100 or 255 characters). SQLite has no date type of its own; storing dates as ISO 8601 text such as 2024-03-05 keeps them sortable and works with its date functions. SQL Server text is written as N’…’ so accented letters and other scripts are stored correctly.

Before you run it

  • Check the CREATE TABLE. The types are a good first guess from your data, but you know the table better: add a PRIMARY KEY, NOT NULL or a longer VARCHAR where it matters.
  • Dates in other formats stay text. Only year-month-day dates (2024-03-05, or 2024-03-05 14:30 with a time) become DATE columns, because a date like 03/05/2024 means March in the US and May in most other countries. Convert them in your spreadsheet first if you want a date column.
  • Column names. Names are kept as written and quoted, so spaces and capitals work. In PostgreSQL that means you’ll have to quote them in every query too; tick snake_case column names to get plain names like order_id instead.
  • Large files. Ticking Wrap in a transaction makes thousands of INSERTs run much faster in most databases, and nothing is saved if one of them fails.