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.
-- SQL output will appear here
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 matches | MySQL | PostgreSQL | SQLite |
|---|---|---|---|
| Integers (optionally signed) | INTEGER (BIGINT โฅ 2^31) | INTEGER (BIGINT โฅ 2^31) | INTEGER |
| Numbers with a decimal point | DECIMAL(p,s) | NUMERIC(p,s) | REAL |
| YYYY-MM-DD | DATE | DATE | TEXT |
| YYYY-MM-DD HH:MM[:SS] | DATETIME | TIMESTAMP | TEXT |
| true / false | TINYINT(1) | BOOLEAN | INTEGER (1/0) |
| Anything else | VARCHAR(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:
You get a table definition and one multi-row INSERT, ready to paste into a client:
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
- Paste or upload your CSV. Comma, tab, semicolon, and pipe delimiters are supported.
- Name the table. The name is sanitized the same way column headers are, so
Order Itemsbecomesorder_items. - Set rows per INSERT. Multi-row INSERTs import dramatically faster than one statement per row; 500 is a solid default. Large single statements can hit
max_allowed_packetin MySQL, so split when files get big. - Choose NULL handling. With "Empty โ NULL" on, blank cells become NULL; with it off, blank text cells become empty strings.
- Copy or download the .sql file and run it against your database.
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.