CSV to SQL Converter

Turn CSV rows into INSERT statements and a CREATE TABLE with detected column types, with quotes escaped the way your database expects.

0 characters

Or drop a .csv/.txt file onto the box above.

Database
Statements
Values
CSV

How to use

  1. Paste CSV, drop a .csv file on the box, or press Load sample.
  2. Pick your database under Dialect and type the Table name.
  3. Choose Rows per INSERT, and untick Add CREATE TABLE if the table already exists.
  4. Read any notes under the result: renamed columns, dropped extra values, a split for SQL Server.
  5. Copy to clipboard or Download .sql, or open the result in the SQL Formatter with Format this SQL.

What it writes, and why the escaping differs per database

Joining CSV values into INSERT statements by hand fails on the first name with an apostrophe in it. The fix is not the same everywhere: every database doubles a single quote (O''Brien), but MySQL also reads backslashes as escapes, and SQL Server needs an N before a string that holds characters outside its code page, or they are stored as question marks. This tool applies the rules of the database you pick under Dialect, and the site's tests read every generated string back through that dialect's quoting rules, and run the SQLite output in a real SQLite database, to check that each value arrives unchanged.

With Add CREATE TABLE on, each column gets the narrowest type that fits every value in it: whole numbers become INTEGER or BIGINT, decimals get a DECIMAL with exactly the precision and scale the data needs, true/false becomes a boolean, and real calendar dates become DATE or a timestamp type. Anything else, including a single value that does not fit, makes the column text, sized to its longest value.

It does not guess a primary key, NOT NULL or indexes, because a CSV cannot tell it which column is unique or required; add those to the CREATE TABLE yourself. It never connects to a database or runs anything.

Example

The file that Load sample inserts, with an apostrophe, a comma inside a quoted field, an accented name, a ZIP code with a leading zero and two empty cells:

id,name,city,zip,signup_date,active,balance
1,Ada Lovelace,London,01234,2026-01-15,true,1250.50
2,Seán O'Brien,"Dublin, Ireland",,2026-02-03,false,0
3,Grace Hopper,New York,10001,2026-03-21,true,

becomes, with the default options (Standard SQL, 100 rows per INSERT):

CREATE TABLE my_table (
  id INTEGER,
  name VARCHAR(12),
  city VARCHAR(15),
  zip VARCHAR(5),
  signup_date DATE,
  active BOOLEAN,
  balance DECIMAL(6, 2)
);

INSERT INTO my_table (id, name, city, zip, signup_date, active, balance) VALUES
  (1, 'Ada Lovelace', 'London', '01234', '2026-01-15', TRUE, 1250.50),
  (2, 'Seán O''Brien', 'Dublin, Ireland', NULL, '2026-02-03', FALSE, 0),
  (3, 'Grace Hopper', 'New York', '10001', '2026-03-21', TRUE, NULL);

With SQL Server the second row is (2, N'Seán O''Brien', N'Dublin, Ireland', NULL, '2026-02-03', 0, 0),: text gets the N prefix and the boolean becomes 0, stored in a BIT column. With SQLite, which has no DATE or BOOLEAN type, the columns are id INTEGER, name TEXT, city TEXT, zip TEXT, signup_date TEXT, active INTEGER, balance NUMERIC.

Options explained

Edge cases and common errors

Do the same thing in code

import sqlite3
import pandas as pd

df = pd.read_csv("data.csv", dtype=str)
df.to_sql("my_table", sqlite3.connect("data.db"), index=False)
\copy my_table FROM 'data.csv' WITH (FORMAT csv, HEADER true)

In a program, send the values as query parameters rather than building INSERT text, which is what pandas does above; dtype=str stops it from reading 01234 as the number 1234. The second line is PostgreSQL's psql client loading a file into an existing table. Before loading, Remove Duplicate Lines can drop repeated rows that would break a primary key, and the SQL Formatter lays out the generated script if you want to read it before running it.

CSV to SQL Converter FAQ

Which databases does the output work with?

MySQL and MariaDB, PostgreSQL, SQL Server and SQLite each have their own Dialect setting; Standard SQL suits most other databases. Oracle is not in the list: it accepts several rows in one VALUES list only from Oracle Database 23ai, so for an older version choose 1 (one INSERT per row) and change the CREATE TABLE types to VARCHAR2 and NUMBER.

Why is a ZIP code or phone number written as text?

Because it starts with a zero. Storing 01234 as a number would silently turn it into 1234, so any value with a leading zero is treated as text, and one such value makes the whole column text. In the sample the zip column becomes VARCHAR(5) and 01234 is inserted as '01234', digits intact.

Why does the MySQL output have double backslashes?

MySQL reads a backslash inside a string as the start of an escape, so \t in C:\temp would arrive as a tab. The tool doubles every backslash for MySQL only: ('C:\\temp\\new');. PostgreSQL, SQL Server and SQLite take backslashes literally, so there the same row is ('C:\temp\new');.

How large a CSV can it convert?

The limit is your browser, not a server. A 3 MB file of 50,000 rows converts in about a third of a second on a laptop, and the result is a few megabytes of text you can download. For millions of rows, a database loader is faster than any INSERT script: LOAD DATA INFILE in MySQL, COPY in PostgreSQL, BULK INSERT in SQL Server.

Is my data uploaded anywhere?

No. The conversion runs in your browser with JavaScript, there is no server side that could receive the file, and nothing is stored. You can load the page, disconnect from the network and convert a file with customer data in it. Your browser remembers the options you picked; the CSV itself is not kept.

Runs entirely in your browser: this page is a static file with no server behind it, so nothing you paste can be uploaded. Last reviewed by Parthesh Gupta.