DiagramDB / CSV to SQL

CSV to SQL Converter

Drop in a CSV export and get a CREATE TABLE statement with sensible column types, plus INSERT statements batched for your database.

SQL · 4 rows
CREATE TABLE imported_rows (
  id INTEGER NOT NULL,
  email VARCHAR(32) NOT NULL,
  signup_date DATE NOT NULL,
  plan VARCHAR(16) NOT NULL,
  monthly_fee NUMERIC NOT NULL,
  is_active BOOLEAN NOT NULL,
  zip VARCHAR(16)
);

INSERT INTO imported_rows (id, email, signup_date, plan, monthly_fee, is_active, zip) VALUES
(1, 'ada@example.com', '2026-01-14', 'pro', 29.00, TRUE, '02139'),
(2, 'grace@example.com', '2026-02-02', 'free', 0, TRUE, '10001'),
(3, 'O''Brien, Kate', '2026-02-19', 'team', 99.50, FALSE, NULL),
(4, 'linus@example.com', '2026-03-07', 'pro', 29.00, TRUE, '94107');

Detected columns

Types are inferred from every value in the column. Override any that are wrong: zip codes and phone numbers with leading zeros stay text on purpose.

ColumnTypeNullableLongest value
idno1
emailno17
signup_dateno10
planno4
monthly_feeno5
is_activeno5
zipyes5

Database-specific guides, each with the bulk-import command: CSV to MySQL · CSV to PostgreSQL · CSV to SQL Server · CSV to SQLite · CSV to Oracle

From spreadsheet to table in three checks

  1. Header row. Column names are converted to snake_case so you never need to quote them: “Signup Date” becomes signup_date.
  2. Types. Look at the detected columns table. Identifiers like ZIP codes, phone numbers and account numbers should be text even when they look numeric; the tool keeps values with leading zeros as text, but check the rest.
  3. Keys. If the CSV has no unique column, tick “Add auto-increment id” to give the table a primary key. Then add foreign keys and indexes by hand, or paste the CREATE TABLE into the ER diagram generator to see how it fits your schema.

Money columns come out as NUMERIC/DECIMAL rather than floating point, because floats cannot store amounts like 0.10 exactly. See SQL data types for how each type maps between databases.

Questions

Is my CSV uploaded?

No. The file is read and converted in your browser; nothing is sent to a server. Your last input is remembered in this browser only, and you can clear it on the privacy page.

How are column types chosen?

Every value in a column is checked. If all values are whole numbers the column is INTEGER (BIGINT past 2,147,483,647); all numbers with decimals become NUMERIC/DECIMAL; true/false/yes/no become BOOLEAN; YYYY-MM-DD becomes DATE; ISO date-times become TIMESTAMP; anything else is VARCHAR sized with headroom, or TEXT past 255 characters. Values with leading zeros stay text.

Why batch the INSERT statements?

One multi-row INSERT per few hundred rows is much faster than one statement per row, but a single giant statement can exceed limits such as MySQL’s max_allowed_packet. SQL Server allows at most 1,000 rows per VALUES list, so batches are capped there automatically.

What about very large CSV files?

For hundreds of thousands of rows, use the database’s bulk loader instead: COPY … FROM in PostgreSQL, LOAD DATA INFILE in MySQL, BULK INSERT or bcp in SQL Server, or .import in SQLite. Use this tool to generate the CREATE TABLE, then bulk-load the file.

How are quotes and commas inside values handled?

The parser follows RFC 4180: fields wrapped in double quotes may contain commas, line breaks and doubled quotes (""). In the SQL output, single quotes are escaped by doubling them, which is standard across all five databases.

Related tools