FormatterHQ

CSV to SQL Converter

Generate SQL from a CSV file: a CREATE TABLE statement with inferred column types plus INSERT statements, with quoting for MySQL, PostgreSQL or SQL Server.

Input CSV
Output SQL
Ready.

How to use the CSV to SQL Converter

  1. Paste CSV, upload or drop a file, use Load URL, or click Sample.
  2. Enter a Table name and choose Identifier quoting for your database: MySQL backticks, PostgreSQL / ANSI quotes, SQL Server brackets or None.
  3. Decide on Include CREATE TABLE, Single multi-row INSERT and Detect numbers & booleans.
  4. Click Convert to SQL, review the statements, then copy or download the .sql script.

CSV to SQL: a ready-to-run import script

Database clients have import wizards, but they are not always available, and sometimes you just want a script you can review, commit or send to a colleague. This CSV to SQL converter reads your file and writes plain SQL: an optional CREATE TABLE whose column types are inferred from the data, followed by INSERT statements for every row.

Example

order_id,customer,total,paid,placed_at,ship_date
1001,O'Brien Ltd,249.99,true,2024-05-02 14:30:00,2024-05-04
1002,Acme,80,false,2024-05-03 09:15:00,

With the table name orders and MySQL quoting:

CREATE TABLE `orders` (
  `order_id` INT,
  `customer` VARCHAR(255),
  `total` DECIMAL(18,6),
  `paid` BOOLEAN,
  `placed_at` DATETIME,
  `ship_date` DATE
);

INSERT INTO `orders` (`order_id`, `customer`, `total`, `paid`, `placed_at`, `ship_date`) VALUES (1001, 'O''Brien Ltd', 249.99, TRUE, '2024-05-02 14:30:00', '2024-05-04');
INSERT INTO `orders` (`order_id`, `customer`, `total`, `paid`, `placed_at`, `ship_date`) VALUES (1002, 'Acme', 80, FALSE, '2024-05-03 09:15:00', '');

Look at the customer name: SQL string literals are delimited by single quotes, so the apostrophe in O'Brien is written twice. Numbers and booleans go in unquoted, and every other value becomes a quoted string.

Column type detection

When Include CREATE TABLE is ticked, the converter scans every column and picks the narrowest type that fits all of its non-empty cells:

Column contentsChosen type
Whole numbersINT, or BIGINT above 2,147,483,647
Any decimalsDECIMAL(18,6)
Only true/falseBOOLEAN
Dates like 2024-05-04DATE
Date and timeDATETIME with backticks, TIMESTAMP with ANSI quotes, DATETIME2 with brackets
Other textVARCHAR(255), or TEXT if any value is longer

These guesses come from a sample of your data, not from its meaning. Review them, and add a primary key, constraints and realistic string lengths before the table goes live. If you untick Detect numbers & booleans, numbers stay strings, so those columns fall back to VARCHAR(255) and their values are quoted; dates are still recognized.

Options explained

  • Table name – the target table, my_table unless you change it.
  • Identifier quoting – pick the style of your database: `backticks` for MySQL and MariaDB, "double quotes" for PostgreSQL, SQLite and other ANSI-style engines, [brackets] for SQL Server. With None, plain names such as order_id are written bare, and only a header like full name falls back to double quotes.
  • Include CREATE TABLE – switch it off to append rows to a table that is already defined.
  • Single multi-row INSERT – groups all rows into one statement, one parenthesized tuple per line. That loads noticeably faster, but a huge statement can hit limits such as MySQL's max_allowed_packet, so split big files.
  • Nest dotted headers and Flatten nested objects – only relevant for dotted headers; with both at their defaults, columns keep their names.

Good uses and limits

Generated INSERT scripts are ideal for seed data, fixtures in a test database, small reference tables such as countries or plan tiers, and one-off migrations that you want to keep in version control. They are readable, easy to diff and run in any SQL client.

For very large files, the native bulk loaders are faster: LOAD DATA INFILE in MySQL, COPY in PostgreSQL and BULK INSERT in SQL Server read the CSV directly. If you run a long script anyway, put it inside a transaction; then one bad row rolls everything back instead of leaving a partial import.

Column names that are reserved words, such as order or group, must be quoted. Pick the quoting style of your database instead of None whenever headers might clash with SQL keywords.

Things to check before running the script

  • Empty cells become empty strings (''), not NULL. In a DATE or numeric column, strict databases reject that, as with ship_date above. Replace '' with NULL for those columns.
  • Booleans on SQL Server – T-SQL uses BIT columns holding 1 or 0, so edit the generated BOOLEAN type and the TRUE/FALSE values before running the script there.
  • IDs with leading zeros stay text, so a column mixing 0042 and 42 becomes VARCHAR. That is usually correct for codes.

Tidy the generated script with the SQL formatter. Starting from an API response instead of a spreadsheet? JSON to SQL handles that case, and SQL to CSV extracts rows from existing INSERT statements.

Privacy

The SQL is generated in your browser and the CSV is not uploaded, so customer or order data stays with you. Loading a file by URL and saving a share link are the only actions that involve our server.

Frequently asked questions

How do I insert NULL instead of empty strings?
Empty cells are written as ''. After converting, replace '' with NULL in the columns that need it, or leave the column out of the CSV and let the database apply its default.
Which databases does the output work with?
The statements are standard INSERT and CREATE TABLE syntax. Choose MySQL backticks for MySQL and MariaDB, ANSI quotes for PostgreSQL, SQLite and Oracle, and brackets for SQL Server, then adjust types such as BOOLEAN where your database differs.
Why is a numeric column typed as VARCHAR?
At least one value in the column is not a plain number, for example it has a leading zero, a thousands separator or a unit. Either clean those values or keep the column as text.
Can I generate only INSERT statements?
Yes. Untick Include CREATE TABLE and the output contains only the inserts for an existing table.
How are quotes in values escaped?
Single quotes are doubled, so O'Brien becomes 'O''Brien'. Identifiers are escaped according to the chosen quoting style.

Last updated September 26, 2026

Related tools