Online CSV to SQL Tool: Import Tabular Data into Databases
What is CSV to SQL
Turn a CSV table into paste-ready INSERT statements for seeding a dev database, documenting examples, or one-off small moves. Try CSV to SQL — the same input can also emit a Markdown or HTML table.
Example matching this site's MySQL-style output
CSV:
id,name,email,age
1,Alice,alice@example.com,28
2,Bob,bob@example.com,32
SQL (backtick identifiers; every non-empty value is a quoted string — numbers are not bare):
INSERT INTO `users` (`id`, `name`, `email`, `age`) VALUES
('1', 'Alice', 'alice@example.com', '28'),
('2', 'Bob', 'bob@example.com', '32');
Switch the dialect control to PostgreSQL and identifiers become "users" / "id" instead. If you need true integer columns, load into a staging table and INSERT ... SELECT CAST(...) — the converter does not invent types.
Why this step still exists
- Dev seed data — tens to hundreds of rows; hand-writing INSERT is slow
- Docs / README samples — Markdown table mode pastes into documentation
- Pre-integration fixtures — pair with CSV/JSON from API samples
- Not million-row production ETL — use
COPY/LOAD DATA/ a real pipeline
How to use (real UI)
- Paste CSV (header on the first row)
- Choose output: SQL INSERT / Markdown Table / HTML Table
- In SQL mode, set the table name (default
my_table) and identifier style (MySQL backticks or PostgreSQL double quotes) - Convert and copy
Delimiter: the parser accepts a custom delimiter argument, but the UI currently fixes comma. Normalize semicolon CSV via CSV/TSV first.
Implementer's notes (parseCSV / csvToSQL)
Parsing
- Quoted fields,
""escapes, and newlines inside quotes are supported - Headers are trimmed; blank lines skipped
- A leading UTF-8 BOM is stripped before parse (Excel-exported CSV no longer poisons the first header as
id) - Short rows pad missing columns with empty strings (more lenient than the bidirectional CSV/JSON tool, which throws on width mismatch)
- The literal text
null/NULLis not treated as SQL NULL — only an empty cell becomesNULL
SQL emission
- Identifiers: MySQL style doubles internal backticks; PostgreSQL style doubles internal
" - Values: empty →
NULL; otherwise'...'with'→'' - No bare numbers, no boolean detection, no date parsing
- One multi-row
INSERT ... VALUES (...), (...);
Markdown / HTML
- Markdown escapes
|inside cells as\|so pipes do not break the table - HTML entity-escapes
& < > "for safe static previews
Excel quirks that remain outside the converter
- Date serials and dropped leading zeros are export-time problems — re-export those columns as text
- European semicolon CSV still needs a delimiter pass first
Large-file boundary
- Building a giant SQL string in a tab will stutter; fine for demos, not for tens of thousands of rows
- No transactions, no
ON CONFLICT, no batch-size control — wrap and key the import yourself for idempotent reruns
RFC 4180's four edges (read side)
- Comma inside a field → must quote
- Quote inside a field → double it (
""), not backslash - Newline inside quotes → legal;
wc -ldisagrees with logical rows - UTF-8 BOM → stripped at parse start here; still strip before
COPY/LOADelsewhere
INSERT vs COPY / LOAD
| Path | Use when | Notes |
|---|---|---|
| Batched INSERT here | Small tables, demos, docs | Choose MySQL or PostgreSQL quoting |
PostgreSQL COPY ... CSV HEADER | Large files | Fast; watch encoding |
MySQL LOAD DATA | Large files | Path + LOCAL security trade-offs |
| SQLite | Multi-INSERT in a transaction | No native CSV bulk (extensions aside) |
Production pattern: TEXT staging → visible CAST / :: → final table. Keep type decisions in reviewable SQL, not converter magic.
Excel dialect and repeatable imports
- Separator: some locales export
;— normalize with CSV/TSV - Leading zeros / dates: set columns to text in the spreadsheet before export
- Idempotent reruns: this tool does not emit
ON CONFLICT/REPLACE—DELETE/TRUNCATEdemo tables, or wrap your own upsert
Treat CSV→SQL as visible scaffolding. Leave types and conflict policy in SQL you can review.
Cluster links
| Step | Tool |
|---|---|
| Tables ↔ objects | CSV/JSON, JSON→CSV |
| Separators | CSV/TSV |
| INSERT layout | SQL formatter |
| Config side path | YAML↔JSON |
| Posts | CSV/JSON, JSON/CSV, SQL formatter |
FAQ
Newlines inside fields?
Wrap the field in double quotes. The parser tracks quote state; it does not only split on physical lines.
Why are numbers quoted?
Everything inserts as text so 00123 stays intact. Cast in SQL after load.
Does the string null become SQL NULL?
No. Only empty cells → NULL. Intentional, so the legitimate text null is not eaten.
PostgreSQL syntax errors?
Pick PostgreSQL in the dialect control, or manually change `col` to "col". String escaping with '' is shared.
Slow bulk import?
Use this tool for small sets; use COPY/LOAD DATA for bulk, optionally defer non-critical indexes and commit in batches.
Transactions and review before you paste
Generated INSERTs are easy to run twice by accident. Wrap a seed block in BEGIN / ROLLBACK while you spot-check row counts, then COMMIT only after SELECT COUNT(*) looks right. Prefer a disposable schema or table suffix (_seed) on shared dev databases. The SQL formatter helps reviewers scan wide INSERT lists; it does not validate types — keep CAST / :: in hand-written follow-up SQL.
Identifiers vs string literals
MySQL backticks and PostgreSQL double quotes protect identifiers (column names with spaces or reserved words). They are not string quotes — values still use single quotes with '' escaping. Mixing the two ("hello" as a value in PostgreSQL) creates a column reference and a confusing “missing column” error that looks unrelated to CSV. Pick the dialect control on CSV to SQL before copying.
From ToolVault. Related: CSV→SQL, CSV/JSON, SQL formatter, CSV/TSV. More on the homepage.
Related Tools
Related Articles
HTML Table to JSON: How to Preserve Rows, Columns and Structure
Converting an HTML table from a web page to JSON — how to keep headers, handle merged cells and nested structure? Step-by-step with our HTML table to JSON tool.
Excel to JSON: Dates Become Numbers / Chinese Garbled — Fix
When converting Excel to JSON, dates turn into numbers like 44927, Chinese is garbled, empty cells vanish? Explains Excel serial dates and encoding pitfalls, with our Excel to JSON tool.
The Complete Guide to Table Format Conversion: Excel, CSV, JSON, Markdown, and HTML
Convert between Excel, CSV, JSON, Markdown, and HTML tables — delimiters, headers, empty cells, merged-cell boundaries, and matching browser tools.