DevToolPal
EN

CSV to SQL Converter

Turn CSV into CREATE TABLE and INSERT statements for MySQL, PostgreSQL, SQLite or SQL Server, with inferred column types.

Runs locally, never uploaded

Options

Input

0 chars · 0 B

Output

0 chars · 0 B

What it does

Loading a spreadsheet into a database usually means writing a table definition and a long list of INSERT statements by hand, escaping every apostrophe along the way. This tool does it for you: paste CSV and get a ready-to-run SQL script with a CREATE TABLE statement and batched multi-row INSERT statements.

It handles quoted fields, commas and line breaks inside cells, and doubled quotes, following RFC 4180. Strings are escaped correctly for the chosen database, including backslashes in MySQL and N'…' Unicode strings in SQL Server.

How to use it

  1. Paste CSV, upload a .csv or .tsv file, or click Sample.
  2. Enter the Table name. Use a dot for a schema, such as public.orders or dbo.orders.
  3. Pick the Dialect: MySQL / MariaDB, PostgreSQL, SQLite or SQL Server.
  4. Choose Rows per INSERT, and switch off CREATE TABLE if the table already exists.
  5. Copy the SQL or download it as a .sql file and run it with your database client.

The delimiter is detected automatically; you can also set comma, semicolon, tab or pipe explicitly. If the first row is data rather than column names, switch off First row is header and the columns are named column_1, column_2 and so on.

Example

This CSV:

id,name,price,in_stock
1,Ada's Tea,4.50,true
2,Coffee,,false

becomes this script for PostgreSQL:

CREATE TABLE "products" (
  "id" INTEGER,
  "name" TEXT,
  "price" NUMERIC(3, 2),
  "in_stock" BOOLEAN
);

INSERT INTO "products" ("id", "name", "price", "in_stock") VALUES
  (1, 'Ada''s Tea', 4.50, TRUE),
  (2, 'Coffee', NULL, FALSE);

The apostrophe in Ada's is doubled, the empty price becomes NULL, and numbers and booleans are written without quotes.

Types and dialects

  • MySQL / MariaDB: backtick identifiers, INT, DECIMAL, BOOLEAN, DATE, DATETIME, VARCHAR(255) or TEXT; backslashes in strings are escaped.
  • PostgreSQL: double-quoted identifiers, INTEGER, NUMERIC, BOOLEAN, DATE, TIMESTAMP and TEXT.
  • SQLite: double-quoted identifiers and SQLite’s storage classes INTEGER, REAL and TEXT; booleans are written as 1 and 0.
  • SQL Server: bracketed identifiers, INT, DECIMAL, BIT, DATE, DATETIME2 and NVARCHAR, with N'…' string literals and at most 1000 rows per INSERT.
  • Empty cells become NULL. Switch off Empty cells as NULL to keep empty strings in text columns.
  • Review the inferred types before running the script on production data: a column that only has small numbers in the sample may need a wider type later.

FAQ

› Which databases are supported?

MySQL (and MariaDB), PostgreSQL, SQLite and Microsoft SQL Server. The dialect controls how table and column names are quoted, how strings are escaped, which column types are used and how booleans are written.

› How are column types chosen?

Each column is scanned: whole numbers become INT or BIGINT, decimals become DECIMAL with enough precision, true/false becomes BOOLEAN (BIT in SQL Server), ISO dates become DATE or DATETIME, and anything else becomes text. Numbers with leading zeros, such as ZIP codes, stay text. Turn off Detect types to make every column text.

› Why is SQL Server limited to 1000 rows per INSERT?

SQL Server rejects a VALUES list with more than 1000 rows, so larger batch sizes are capped at 1000 for that dialect. Other databases accept bigger batches, but 100 to 1000 rows per statement is a good balance between speed and statement size.

› Is my CSV uploaded?

No. Parsing and SQL generation happen entirely in your browser, so the data never leaves your device.