Tools / CSV to SQL
CSV to SQL Converter
Turn a CSV file into a CREATE TABLE statement and INSERT statements for PostgreSQL, MySQL, SQLite or SQL Server. Column types are detected for you.
Free, no sign-up. Everything runs in your browser, so your data is never uploaded.
How to use it
- Paste a CSV with a header row, or open a file. The delimiter is detected automatically.
- Choose your database and a table name. Column names are cleaned into safe SQL identifiers, such as
Order Datebecomingorder_date. - Click Generate SQL, check the detected column types, then copy the SQL or download it and run it in your database client.
How column types are chosen
Each column gets the narrowest type that fits every non-empty value in it:
| Values in the column | PostgreSQL | MySQL | SQLite | SQL Server |
|---|---|---|---|---|
| Whole numbers | INTEGER or BIGINT | INT or BIGINT | INTEGER | INT or BIGINT |
| Decimals | NUMERIC | DECIMAL(p,s) | REAL | DECIMAL(p,s) |
| true/false | BOOLEAN | BOOLEAN | INTEGER | BIT |
| Dates (2025-03-15) | DATE | DATE | TEXT | DATE |
| Date and time | TIMESTAMP | DATETIME | TEXT | DATETIME2 |
| Anything else | TEXT or VARCHAR(n) | VARCHAR(n) or TEXT | TEXT | NVARCHAR(n) |
Numbers with leading zeros, like ZIP codes, are kept as text. Only ISO dates (YYYY-MM-DD) are treated as dates, because formats like 03/04/2025 are ambiguous. Always review the types before loading production data.
Faster ways to load big files
INSERT statements are fine for thousands of rows. For millions, use your database’s bulk loader, which is much faster:
-- PostgreSQL (psql)
\copy my_table FROM 'data.csv' WITH (FORMAT csv, HEADER true)
-- MySQL
LOAD DATA LOCAL INFILE 'data.csv' INTO TABLE my_table
FIELDS TERMINATED BY ',' ENCLOSED BY '"' IGNORE 1 LINES;
-- SQLite
.import --csv --skip 1 data.csv my_tableOr from Python with pandas: df.to_sql("my_table", engine, if_exists="replace", index=False). Once the data is in, our SQL for data analysis tutorial shows how to query it.
FAQ
Is my CSV uploaded?
No. The SQL is generated in your browser and nothing is sent to our server.
Are quotes in my data escaped safely?
Yes. Single quotes inside text are doubled (O'Brien becomes 'O''Brien'), which is the standard SQL escape in all four databases.
Can I add a primary key?
Add it after loading, for example ALTER TABLE my_table ADD PRIMARY KEY (order_id);. The converter doesn’t guess keys, because a column that looks unique in a sample may not be.
Related
- SQL for data analysis
- Excel to CSV converter: convert a spreadsheet first, then generate SQL
- CSV to JSON converter
