How to convert CSV to SQL
The fastest way: drop your CSV into the converter at the top of this page, name your table, click Generate SQL. The tool produces ready-to-paste INSERT statements with proper escaping. Runs entirely in your browser using PapaParse — no upload.
- Upload your CSV or paste the contents into the input.
- Set the table name (defaults to
my_table). - Pick the SQL dialect — MySQL, PostgreSQL, SQLite, or generic ANSI SQL. Each has slightly different escaping rules and quote characters.
- Choose the statement style:
- Multi-row INSERT — one statement per N rows (fast for big imports).
- Single-row INSERTs — one statement per row (more verbose, easier to read).
- Include CREATE TABLE — generates a schema with column types auto-detected from the data.
- Click Generate SQL. Copy the output to your SQL console, or download as a
.sqlfile.
Going the other direction? See “How to export SQL query results to CSV” further down.
How to convert CSV to SQL insert statements
The most common form of “csv to sql” is generating INSERT INTO ... VALUES (...) statements. The converter above does this by default. Given a CSV like:
id,name,email,signup_date
1,Ada,ada@lovelace.io,2024-03-12
2,Linus,linus@kernel.example,2023-11-05
It generates:
INSERT INTO my_table (id, name, email, signup_date) VALUES
(1, 'Ada', 'ada@lovelace.io', '2024-03-12'),
(2, 'Linus', 'linus@kernel.example', '2023-11-05');
Notice the converter:
- Quotes strings with single quotes (escaping internal
'as''). - Leaves numbers unquoted so they’re stored as integers/floats.
- Quotes dates as strings (your DB will parse them on insert if the column type is DATE).
- Treats empty values as NULL rather than empty strings.
Pick the multi-row INSERT option for bulk imports — it’s 10–100× faster than single-row INSERTs on most databases.
How to convert CSV to SQL query without code
The converter above is the no-code path. Three other options:
1. Database GUI clients
Tools like TablePlus, DBeaver, HeidiSQL, and DataGrip can import CSVs directly via right-click → Import → CSV. They generate the equivalent SQL behind the scenes.
2. Database CLI
Most database CLIs support direct CSV import:
# PostgreSQL
psql -d mydb -c "\copy my_table FROM 'data.csv' DELIMITER ',' CSV HEADER"
# MySQL
mysqlimport --fields-terminated-by=, --ignore-lines=1 mydb data.csv
# SQLite
sqlite3 mydb.db
> .mode csv
> .import data.csv my_table
Faster for million-row imports, but requires database access and command-line comfort. The converter above is faster for ad-hoc data and works without DB credentials.
3. Spreadsheet formula trick (no SQL required)
For one-off imports, build INSERT statements with a formula in Excel/Sheets:
="INSERT INTO my_table VALUES ("&A2&", '"&B2&"', '"&C2&"');"
Drag down, copy the column, paste into your SQL console. Brittle but works in a pinch.
How to convert CSV to MySQL
The converter generates MySQL-compatible SQL by default. Some MySQL-specific notes:
- Backtick-quoted identifiers: pick the MySQL dialect and the converter wraps table/column names in backticks (
`my_table`) — useful when columns have reserved words likeorderorkey. - Bulk insert: use the multi-row INSERT option. MySQL handles batches up to
max_allowed_packet(default 4MB ≈ 50K rows depending on row width). - Loading the file directly: instead of
INSERTs, you can useLOAD DATA INFILE 'data.csv' INTO TABLE my_table FIELDS TERMINATED BY ',' IGNORE 1 ROWS;— much faster for huge files.
How to convert CSV to PostgreSQL
Pick the PostgreSQL dialect and the converter:
- Uses
"double-quoted"identifiers (Postgres standard). - Properly escapes strings using SQL standard
''doubling (no backslash escapes). - Generates
NULLfor empty CSV cells rather than empty strings.
For huge imports, skip the INSERT path entirely and use Postgres’s native \copy command (see CLI example above) — it’s an order of magnitude faster.
How to convert CSV to SQLite
SQLite is loose with types — it stores whatever you give it. Pick the SQLite dialect and the converter:
- Uses ANSI standard escaping (single quotes, doubled).
- Optional CREATE TABLE uses dynamic typing (
TEXT,INTEGER,REAL,NUMERIC). - Wraps the whole script in
BEGIN; ... COMMIT;for atomic imports — much faster than auto-commit per row.
For very large CSVs, the SQLite CLI’s .import is the fastest path. The converter is best for one-off scripts and small-to-medium files.
How to convert CSV to SQL Server
Pick the MS SQL option (or use generic SQL with manual tweaks). SQL Server differences:
- Uses
[bracketed]identifiers as a third option (alternative to double quotes). - Bulk insert via
BULK INSERTreads CSVs natively; the INSERT script is best for small/medium imports. - Dates need
'2024-03-12'format with explicitCAST(... AS DATE)if the column type isn’t already DATE.
How to export SQL query results to CSV
Going the other direction — running a SQL query and saving the results as a CSV — is handled by your database client, not by a converter. Here’s how to do it in the major systems:
Export MySQL query to CSV
SELECT * FROM customers
INTO OUTFILE '/tmp/customers.csv'
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\n';
Requires FILE permission on the MySQL user. From the CLI you can also use mysql -e "SELECT ..." > out.csv and pipe through sed to convert tabs to commas.
Export PostgreSQL query to CSV
\copy (SELECT * FROM customers) TO 'customers.csv' CSV HEADER
This is run from psql (the CLI), not the SQL editor. The \copy (lowercase) command writes to your local machine; COPY (uppercase) writes to the server’s filesystem.
Export SQL Server query to CSV
In SQL Server Management Studio:
- Run your query.
- Right-click the results grid → Save Results As.
- Pick CSV (Comma delimited) in the format dropdown.
Or via sqlcmd:
sqlcmd -S server -d database -Q "SELECT * FROM customers" -s "," -W -o customers.csv
Export SQLite query to CSV
sqlite3 mydb.db
> .headers on
> .mode csv
> .output customers.csv
> SELECT * FROM customers;
> .output stdout
Export from any database via a GUI
DBeaver, TablePlus, HeidiSQL, DataGrip all support right-click on results → Export → CSV without writing any SQL. Often the fastest path for ad-hoc exports.
After exporting, you can view the CSV, convert it to Excel, merge it with another export, or convert it to PDF for sharing.
Common CSV-to-SQL problems
”My SQL won’t run — quote escaping is wrong”
Different databases use different escape rules. The converter handles this when you pick the right dialect. If you copy the output into the wrong dialect, single quotes inside string values (O'Brien) break the query. Pick the matching dialect and regenerate.
”Numbers are being inserted as strings”
The converter auto-detects numeric columns. If a single non-numeric value appears in an otherwise-numeric column (e.g. N/A instead of NULL), the column gets typed as TEXT. Replace N/A with empty values in the CSV before converting, and they’ll become NULL in the SQL.
”Date format errors on insert”
Most databases parse YYYY-MM-DD and ISO timestamps natively. If your CSV has MM/DD/YYYY or some regional format, normalize the dates before converting — or wrap them in STR_TO_DATE() (MySQL) / TO_DATE() (Postgres) / CAST(... AS DATE) (SQL Server) by hand-editing the generated SQL.
”The script is too big to paste”
Multi-row INSERTs help, but past a few hundred thousand rows you should switch to your database’s native bulk loader (LOAD DATA INFILE, \copy, BULK INSERT). The converter at the top of this page handles up to ~50K rows comfortably; past that, generating then pasting the SQL becomes the bottleneck.
Privacy: nothing is uploaded
The CSV-to-SQL conversion runs entirely in your browser using PapaParse for parsing and a small in-house SQL generator for output. No file ever reaches a server — verify in DevTools → Network. Useful when your CSV contains internal data, customer records, or anything you wouldn’t paste into a public converter.
Related tools
Convert any CSV file to a real .xlsx Excel workbook in seconds. Free, no signup, files never leave your browser.
Turn any .xlsx or .xls Excel file into a clean CSV. Pick the sheet, pick the delimiter, download. No upload.
Convert any Excel workbook (.xlsx or .xls) to a printable PDF in seconds. Pick the sheet, pick orientation, download. 100% private.
Convert any CSV file to a clean PDF table in seconds. Free, no signup, files never leave your browser.
Frequently asked questions
- How do I convert CSV to SQL?
Drop your CSV into the converter at the top of this page, name your table, pick a SQL dialect (MySQL, Postgres, SQLite, SQL Server), and click Generate. The tool produces ready-to-paste INSERT statements with proper escaping.
- Does it generate CREATE TABLE too?
Yes — tick the 'Include CREATE TABLE' option and the tool auto-detects column types (INTEGER, REAL, DATE, TEXT) from the data and emits a matching schema.
- What about CSV to SQL insert query specifically?
That's exactly what this tool does. Pick 'Multi-row INSERTs' for one INSERT statement covering many rows (fastest for bulk import), or 'Single-row INSERTs' for one statement per row (verbose, easier to debug).
- Can I convert CSV to MySQL?
Yes — pick the MySQL dialect and the tool uses backtick-quoted identifiers and the right escape rules. For huge imports, you can use MySQL's LOAD DATA INFILE instead — see the article below.
- Can I convert CSV to PostgreSQL?
Yes — pick the PostgreSQL dialect for double-quoted identifiers and standard SQL escaping. For very large CSVs, Postgres's \copy command is the fastest path.
- Can I convert CSV to SQLite?
Yes — pick the SQLite dialect. The output is wrapped in BEGIN/COMMIT for atomic, fast imports. SQLite's loose typing means columns are typed as INTEGER, REAL, NUMERIC, or TEXT.
- Can I export SQL query results to CSV?
Yes, but that's done from your database client, not by uploading anything here. The article below has the exact commands for MySQL (INTO OUTFILE), PostgreSQL (\copy), SQL Server (sqlcmd or SSMS), and SQLite (.mode csv).
- Is my CSV uploaded?
No. The conversion runs entirely in your browser using PapaParse and an in-house SQL generator. Your data never reaches a server. Verify in DevTools → Network.