1xA2ZOne Data. Any Format.
Live syncLocal-first · no data upload

Convert CSV to SQL

Paste a CSV into the Quick paste box and the tool writes a CREATE TABLE and the INSERT statements for your table. Pick the database and table name on the SQL tab, then copy the script to run.

Runs entirely in your browser. Your data is never uploaded. Tiếng Việt

01

Spreadsheet

SheetsExcelCSVTSV
✦ Quick pasteSheets / Excel, CSV, TSV, Markdown, JSON, HTML, LaTeX, wiki…
0 rows · 0 columnsSelected cell: A1
02

Live Output

Markdowntwo-way
SyncedEdit directly; the table on the left updates itself
0 characters
Every change is processed right in your browserReady · LocalUTF-8 · by xuanhieu.org

When you need to convert CSV to SQL

You have a CSV and need it in a database quickly, to try queries, to build sample data or to move figures out of a spreadsheet. Hand-writing hundreds of INSERT lines is error-prone, especially with names like O'Brien that contain an apostrophe. The tool doubles the apostrophes, quotes column names the way each dialect expects and merges the rows into one statement. In return the output is always text-typed, with no keys or indexes.

How to do it

  1. Paste the CSV into the Quick paste box and press Load into table ↵, or use Import file with a .csv file.
  2. The first CSV row becomes the column names. Edit the headers in the grid if you want shorter column names.
  3. Open the SQL tab and ⚙ Options. Enter the table name, choose the database dialect, and decide whether to include CREATE TABLE or DROP TABLE IF EXISTS.
  4. Press Copy result and paste into your query tool, or Download file for a .sql file.
  5. Try it on a test database before running it on real data.

A real example

Column names are wrapped in backticks, MySQL style, and O'Brien & Co became 'O''Brien & Co' with the apostrophe doubled. The quantity 120 still sits inside quotes and its column is TEXT, because every value is written as a string.

Input · CSV

Code,Brand,Qty,Location
P-100,O'Brien & Co,120,Shelf A
P-101,L'Oréal,45,Shelf B
P-102,Dell,8,Shelf A

Result · SQL

CREATE TABLE `stock` (
  `Code` TEXT,
  `Brand` TEXT,
  `Qty` TEXT,
  `Location` TEXT
);
INSERT INTO `stock` (`Code`, `Brand`, `Qty`, `Location`) VALUES
  ('P-100', 'O''Brien & Co', '120', 'Shelf A'),
  ('P-101', 'L''Oréal', '45', 'Shelf B'),
  ('P-102', 'Dell', '8', 'Shelf A');

Options worth changing

Database
Pick the engine you will run it on: MySQL / MariaDB quotes names with backticks, SQL Server uses square brackets, Standard / PostgreSQL / SQLite uses double quotes. The wrong choice can fail with a syntax error when you run it.
Table name
Set the target table name, for example stock. It appears in both the CREATE TABLE and the INSERT.
Batch INSERT
On, one INSERT holds many VALUES rows, which is more compact. Turn it off if your tool limits statement length or you want one statement per row.
Include DROP TABLE IF EXISTS
Turn it on to rebuild the table from scratch. Be careful: it removes any existing table of that name before creating the new one.

Common problems

Limits

Frequently asked questions

Does this work for PostgreSQL and SQLite?

Yes. Choose the PostgreSQL / SQLite entry under Database and column names are wrapped in double quotes.

Why are numbers inside quotes?

The grid holds only strings, so every value is quoted and leading zeros are never lost. Your database usually converts when loading into a numeric column.

Will it create a primary key?

No. Add keys and indexes with ALTER statements after the data is loaded.

Does it handle large files?

Up to 10,000 rows per table. Split anything bigger before converting.

Does my data leave my computer?

No. The statements are generated in your browser.

Related conversions

1xA2Z · Guide

Table statistics