CSV to SQL Converter

Paste a CSV (or upload the file), pick MySQL, PostgreSQL, or SQLite, and this converter writes the SQL for you: a CREATE TABLE statement with an inferred type for every column, followed by batched INSERT statements with strings properly escaped. Quoted fields with commas, doubled quotes, and custom delimiters all parse correctly per RFC 4180, and nothing leaves your browser โ€” the whole conversion runs locally, so customer exports stay private.

๐Ÿ“Ž Upload CSV
CSV Input
0 rows ยท 0 cols
SQL Output
0 statements
-- SQL output will appear here
Advertisement

Type Inference: CSV Pattern to SQL Type

The converter scans every value in a column before committing to a type. An id column of whole numbers becomes INTEGER; a price column with decimals becomes an exact DECIMAL sized to the data; ISO dates become DATE. Here is the full mapping for each dialect:

Every value in the column matchesMySQLPostgreSQLSQLite
Integers (optionally signed)INTEGER (BIGINT โ‰ฅ 2^31)INTEGER (BIGINT โ‰ฅ 2^31)INTEGER
Numbers with a decimal pointDECIMAL(p,s)NUMERIC(p,s)REAL
YYYY-MM-DDDATEDATETEXT
YYYY-MM-DD HH:MM[:SS]DATETIMETIMESTAMPTEXT
true / falseTINYINT(1)BOOLEANINTEGER (1/0)
Anything elseVARCHAR(n)VARCHAR(n)TEXT

Precision is computed from the data itself: a column whose widest value is 84500.50 gets DECIMAL(7,2) โ€” five integer digits plus two decimals. VARCHAR length is the longest observed value, so Alice Johnson sets VARCHAR(13). Identifiers are quoted per dialect (backticks for MySQL, double quotes for PostgreSQL and SQLite), and column names like First Name! are sanitized to first_name.

A Worked Example

Feed this three-row CSV (note the quoted field with a comma) into the converter with MySQL selected and table name employees:

id,first_name,hire_date,salary,active 1,Alice Johnson,2021-03-15,84500.50,true 2,"Nguyen, Bao",2022-11-02,91200,false 3,Carlos Diaz,2020-07-30,78000.25,true

You get a table definition and one multi-row INSERT, ready to paste into a client:

CREATE TABLE `employees` ( `id` INTEGER, `first_name` VARCHAR(13), `hire_date` DATE, `salary` DECIMAL(7,2), `active` TINYINT(1) ); INSERT INTO `employees` (`id`, `first_name`, `hire_date`, `salary`, `active`) VALUES (1, 'Alice Johnson', '2021-03-15', 84500.50, 1), (2, 'Nguyen, Bao', '2022-11-02', 91200, 0), (3, 'Carlos Diaz', '2020-07-30', 78000.25, 1);

The same input under PostgreSQL swaps in NUMERIC(7,2), BOOLEAN, and the literals TRUE/FALSE; under SQLite every text-ish column collapses to TEXT affinity and booleans become 1/0. One CSV, three dialects, no edits.

How to Use the Converter

Why Generated SQL Beats Import Wizards

Spreadsheet import wizards hide type decisions from you, and the ones they make are often wrong: ZIP codes silently become numbers and lose leading zeros, phone numbers drift into scientific notation. Generating SQL makes every choice visible and editable โ€” you can see that zip landed on VARCHAR(10) and change the line before running it. Because the inference is per-column across all rows, one stray value like N/A in a numeric column demotes that column to VARCHAR rather than crashing an import halfway through.

The parser is a character-by-character RFC 4180 state machine, the same engine behind our CSV to JSON converter. Quoted commas, doubled quotes ("" โ†’ "), newlines inside quoted fields, CRLF endings, and a UTF-8 BOM are all handled. On the way out, single quotes in your data are doubled per the SQL standard, so O'Brien arrives as 'O''Brien' and injection-style content in a CSV can't break out of the string literal.

Going the other direction โ€” a database dump back into a spreadsheet for a stakeholder โ€” the CSV to Excel converter produces a real .xlsx, and the SQL formatter cleans up queries you paste from logs.

Frequently Asked Questions

How do I convert a CSV file to SQL?

Paste the CSV text or upload the file, pick your database dialect (MySQL, PostgreSQL, or SQLite), and name the table. The tool parses the rows, infers a type for every column, and emits a CREATE TABLE statement followed by INSERT statements you can run directly.

How does the converter decide column types?

It scans every value in each column. All integers become INTEGER (BIGINT past 2^31), all numbers with decimals become DECIMAL with the observed precision, YYYY-MM-DD values become DATE, true/false values become BOOLEAN, and anything else becomes VARCHAR sized to the longest value.

Does it handle commas and quotes inside fields?

Yes. The parser follows RFC 4180: a field wrapped in double quotes can contain commas, escaped doubled quotes, and even line breaks. Those values are re-escaped with doubled single quotes in the SQL output so nothing breaks on import.

How many rows can it convert at once?

There is no hard limit; everything runs in your browser, so practical limits are memory (roughly tens of thousands of rows on a typical laptop). Use the batch size option to split large files into multi-row INSERT statements of 500 or 1,000 rows, which is also faster to execute.

Is my CSV data uploaded to a server?

No. Parsing and SQL generation happen entirely in your browser with vanilla JavaScript. Nothing is transmitted, logged, or stored, so the tool is safe for customer lists and other sensitive exports.

Can I import the generated SQL into Excel or JSON instead?

For other destinations use the sister tools: the CSV to Excel converter produces a real .xlsx, and the CSV to JSON converter emits arrays of objects for APIs. This page covers the three SQL dialects.

Advertisement