SmartQueryTools

Convert CSV to SQL Online

Convert CSV files to SQL INSERT statements directly in your browser. Copy or download the generated SQL — no upload required.

About converting CSV to SQL

Generating SQL from a CSV gives you a script to run in any SQL client: a CREATE TABLE statement followed by one INSERT per row. It is the quickest way to move a small CSV into a database when you cannot use a bulk loader, for example a managed database with no file access, a migration file in a Git repository, or seed data for tests.

The script covers the first 1,000 rows, which suits its purpose: fixtures, lookup tables, reference lists and bug reproductions. For bigger files, a bulk loader such as PostgreSQL's \copy, MySQL's LOAD DATA LOCAL INFILE or SQLite's .import is far faster. You can still run the CREATE TABLE from this output first, so the loader has typed columns to fill.

Check dialect details before running it. Table and column names are wrapped in double quotes, which PostgreSQL, SQLite and DuckDB accept but MySQL only accepts with ANSI_QUOTES enabled. Decimal columns are declared as DOUBLE PRECISION, an 8-byte float in PostgreSQL, MySQL and SQLite alike. That suits measurements, but money is safer as DECIMAL. The table is named after your file, with characters other than letters, digits and underscores replaced by underscores.

Worked example

A small orders export with an ID, a customer name, a date, an amount (one missing) and a true/false flag, converted with the default settings.

Input (CSV)

order_id,customer,order_date,amount,shipped
1001,Acme Ltd,2026-03-02,249.5,true
1002,Brightside Co,2026-03-02,1200,false
1003,Acme Ltd,2026-03-05,89.99,true
1004,Northwind,2026-03-07,,false

Output (SQL)

CREATE TABLE IF NOT EXISTS "data" (
  "order_id" BIGINT,
  "customer" TEXT,
  "order_date" DATE,
  "amount" DOUBLE PRECISION,
  "shipped" BOOLEAN
);

INSERT INTO "data" VALUES (1001, 'Acme Ltd', '2026-03-02', 249.5, true);
INSERT INTO "data" VALUES (1002, 'Brightside Co', '2026-03-02', 1200, false);
INSERT INTO "data" VALUES (1003, 'Acme Ltd', '2026-03-05', 89.99, true);
INSERT INTO "data" VALUES (1004, 'Northwind', '2026-03-07', NULL, false);

What changes when you convert CSV to SQL

  • The CREATE TABLE lists every column with a type: order_id BIGINT, customer TEXT, order_date DATE, amount DOUBLE PRECISION, shipped BOOLEAN.
  • Each CSV row becomes its own INSERT INTO ... VALUES (...); statement, in file order.
  • Text and dates are single-quoted. A value such as O'Brien is written as 'O''Brien' so the apostrophe cannot break the statement.
  • Order 1004's empty amount is written as the keyword NULL, not an empty string.
  • The example table is called data. The tool names it after your file, so orders.csv produces a table called orders.
  • Only the first 1,000 rows are included, and a notice appears when the file is longer.

Your file is processed locally in your browser and is never uploaded. The free limit is 50 MB per file; larger files work if your device has the memory for them.

Frequently Asked Questions

Will the script run on MySQL?

Only with a change. MySQL reads double-quoted names as strings unless ANSI_QUOTES is on. Run SET SESSION sql_mode = CONCAT(@@sql_mode, ',ANSI_QUOTES'); first, or replace the double quotes with backticks. For currency columns, change DOUBLE PRECISION to DECIMAL(12,2).

Does it work with SQL Server?

Not as written. SQL Server has no CREATE TABLE IF NOT EXISTS and no BOOLEAN type. Remove IF NOT EXISTS, change BOOLEAN to BIT and TEXT to NVARCHAR(MAX), and replace the bare true and false values with 1 and 0.

Why am I only getting 1,000 INSERT statements?

The SQL output is capped at 1,000 rows so the script stays usable in a browser text box. For the full file, keep the CREATE TABLE statement from here and load the rows with your database's own CSV import.

What is SQL format?

SQL (Structured Query Language) is the standard language for querying and manipulating relational databases. The output contains CREATE TABLE and INSERT INTO statements ready to run against any SQL-compatible database.

Related Tools