DataShift

Convert CSV to SQL INSERT Statements

Generate SQL INSERT statements from any CSV file. Set the table name, choose batch size, and optionally emit a CREATE TABLE statement.

CSV → SQL

Free CSV to SQL converter. Paste CSV data and get SQL INSERT statements ready for any database. Configurable table name, batch inserts, and optional CREATE TABLE. Works in your browser.

100% local — no uploads
Input · CSV

Output will appear here

How to use the CSV → SQL

  1. Paste or upload your CSV data

    Paste text directly into the input box, drag and drop a file onto it, or click "Upload file" to browse. Conversion starts instantly on paste — no button click required.

  2. Configure options (optional)

    Open the Options panel to customise delimiter, headers, nested-object flattening, and more. Use the Field Selector to pick exactly which columns appear in the output.

  3. Copy or download your SQL

    Click Copy to grab the result, or Download to save the file. Everything runs locally in your browser — no data ever leaves your device.

Frequently Asked Questions

Is my data safe?
Yes. Every conversion runs entirely inside your browser. No data is ever transmitted to a server. The tool works offline once loaded.
What is the maximum file size?
There is no hard limit. Files under 1 MB convert instantly. Files 1–10 MB show a progress indicator. Files over 10 MB prompt a warning and run in a background thread to keep the browser responsive.
Why does my CSV fail to parse?
Common causes are trailing commas, single-quoted strings, unquoted keys, or missing closing brackets. The converter auto-repairs many of these and tells you exactly what it changed.
Can I convert multiple files at once?
The tool handles one file at a time. For bulk conversion, consider the csvjson CLI or API.

Related Converters

How it works

Step 1

Column headers become column names

The first row of your CSV becomes the column list in the INSERT statement. Column names are automatically backtick-quoted to handle spaces and reserved words.

Step 2

Values are properly escaped

String values are single-quoted with internal single quotes doubled. Numbers stay unquoted. Empty cells and nulls become SQL NULL. No manual escaping required.

Step 3

Batch inserts for performance

Instead of one INSERT per row, batch mode groups multiple rows into a single INSERT VALUES (...), (...) statement. A single statement with 1,000 rows is dramatically faster than 1,000 individual INSERTs.

Example

Product catalog CSV imported into a PostgreSQL products table

Input
sku,name,price,stock
SHOE-BLK-42,Black Running Shoe,89.99,143
SOCK-GRY-M,Grey Wool Sock,7.99,891
HAT-RED-L,Red Baseball Cap,24.99,52
Output
INSERT INTO `products` (`sku`, `name`, `price`, `stock`) VALUES
  ('SHOE-BLK-42', 'Black Running Shoe', 89.99, 143);
INSERT INTO `products` (`sku`, `name`, `price`, `stock`) VALUES
  ('SOCK-GRY-M', 'Grey Wool Sock', 7.99, 891);

Numbers stay unquoted. String values are single-quoted with apostrophes escaped.

Edge cases, handled

Values containing single quotes

A product name like "O'Brien Surfboard" has its apostrophe doubled: 'O''Brien Surfboard'. This is standard SQL escaping that works in MySQL, PostgreSQL, and SQLite.

Empty cells → NULL

An empty CSV cell becomes SQL NULL, not an empty string. This preserves the distinction between 'no value' and 'empty string' in your database.

Reserved word column names

Column names that are SQL reserved words (like 'order', 'group', 'select') are backtick-quoted automatically so the INSERT statement is valid.

Frequently asked questions

Which databases does this work with?

The output uses backtick quoting for identifiers, which is MySQL and MariaDB syntax. For PostgreSQL, replace backticks with double quotes. For SQLite, both backticks and double quotes work. The VALUES syntax is standard across all major databases.

What's the benefit of batch inserts?

A single INSERT with 1,000 value rows is typically 10-100x faster than 1,000 individual INSERTs. Each INSERT requires a round-trip to the database, a transaction commit, and index updates. Batching amortizes that overhead across many rows.

Can I generate a CREATE TABLE statement too?

Yes. Enable 'Include CREATE TABLE' in the options and the output starts with a CREATE TABLE IF NOT EXISTS statement using TEXT for all column types. You can edit the column types after generating.

How are numbers handled?

Values that look like integers or decimals (matching -?[0-9]+(.[0-9]+)?) are inserted without quotes. Everything else is treated as a string. If a column contains mixed types, some rows will be quoted and others won't — you may want to cast in your SQL instead.