DataSwitch Pro Private, in-browser data converter

CSV to SQL Converter

Generate ready-to-run INSERT statements — and optionally CREATE TABLE — from any CSV file.

Copied to clipboard!
Rows
0
Columns
0
Delimiter
—
Input Size
0 B
Output Size
0 B
Speed
0 ms

How to convert CSV to SQL

Updated · 3 min read

Getting spreadsheet data into a database is a daily task for developers and analysts. This converter turns CSV rows into SQL INSERT statements with correctly quoted identifiers and escaped values for the database you use, and can generate a CREATE TABLE statement with column types detected from the data.

  1. Paste the CSV or drop a file — the delimiter is detected automatically.
  2. Under Options, choose the SQL dialect and type the table name (schema-qualified names such as sales.orders work too).
  3. Tick Add SQL CREATE TABLE to generate the table definition, and Empty cells as NULL if blanks should be NULL.
  4. Copy the SQL into your database client or download the .sql file.

Example

CSV input

id,customer,amount,paid,order_date
1,O'Neil,120.50,true,2026-10-01
2,"Benali, Karim",89,false,2026-10-03

SQL output

CREATE TABLE IF NOT EXISTS "orders" (
  "id" INTEGER,
  "customer" TEXT,
  "amount" DOUBLE PRECISION,
  "paid" BOOLEAN,
  "order_date" DATE
);

INSERT INTO "orders" ("id", "customer", "amount", "paid", "order_date") VALUES
(1, 'O''Neil', 120.5, TRUE, '2026-10-01'),
(2, 'Benali, Karim', 89, FALSE, '2026-10-03');

The apostrophe in O'Neil is escaped by doubling it, identifiers are quoted for PostgreSQL, and the generated table uses INTEGER, DOUBLE PRECISION, BOOLEAN, DATE and TEXT based on the values.

Your data stays on your device. The conversion runs in JavaScript inside this tab — files and pasted text are never uploaded to DataSwitch Pro.

Dialect differences handled for you

DialectIdentifiersBooleansStrings
MySQL / MariaDB`name`TRUE / FALSEBackslashes escaped
PostgreSQL"name"TRUE / FALSEStandard quoting
SQLite"name"TRUE / FALSEStandard quoting
SQL Server[name]1 / 0N'…' for Unicode

CREATE TABLE and column types

Types are inferred from all values in each column: whole numbers become INTEGER (or BIGINT beyond 2.1 billion), decimals become a floating-point type, true/false become BOOLEAN (BIT on SQL Server), ISO dates become DATE, and text becomes VARCHAR(255) or TEXT. Treat the generated definition as a starting point: add primary keys, NOT NULL constraints and exact DECIMAL precision for money before using it in production.

Large files

Rows are grouped into multi-row INSERT statements of 1,000 rows each — fast to execute and within SQL Server's per-statement limit. For files with millions of rows, the database's bulk loader is faster still: LOAD DATA in MySQL, COPY in PostgreSQL or .import in SQLite (examples below).

NULL, empty strings and quotes

By default an empty CSV cell becomes an empty string ''. Tick Empty cells as NULL to insert NULL instead, which is usually what you want for numbers and dates. The text NULL in a cell always becomes SQL NULL. Single quotes inside values are doubled, so names like O'Brien never break the statement.

Convert CSV to SQL in code

For one-off files the tool above is quickest. To automate the same task in a script or pipeline, these snippets are a good starting point.

MySQL bulk load

LOAD DATA LOCAL INFILE 'orders.csv' INTO TABLE orders
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES;

PostgreSQL bulk load (psql)

\copy orders FROM 'orders.csv' WITH (FORMAT csv, HEADER true)

Python (pandas + SQLite)

import sqlite3
import pandas as pd

df = pd.read_csv("orders.csv")
df.to_sql("orders", sqlite3.connect("shop.db"), index=False, if_exists="append")

Frequently asked questions

Which databases are supported?

MySQL and MariaDB, PostgreSQL, SQLite and Microsoft SQL Server. The statements also work in most databases compatible with these, such as Amazon Aurora, CockroachDB (PostgreSQL mode) and Azure SQL.

Can I use a schema-qualified table name?

Yes. Enter dbo.customers or sales.orders; each part is quoted separately.

Are the column names quoted?

Yes, always, so names with spaces or reserved words such as order or group work.

How are booleans written?

TRUE and FALSE for MySQL, PostgreSQL and SQLite; 1 and 0 for SQL Server, which has no boolean literal.

Is my CSV uploaded?

No. The SQL is generated in your browser and nothing is sent to a server.

Related converters