CSV → SQL INSERT / UPSERT
Paste CSV with a header row to generate dialect-aware, batched INSERT statements — or an UPSERT keyed on your unique columns. Column types are inferred; a rollback DELETE and validation report sit in the extended view. Runs in your browser.
Auto-generates as you type. Ctrl+Enter to re-run.
How to use the CSV → SQL INSERT / UPSERT Generator
Convert a CSV (or pasted spreadsheet) into dialect-aware INSERT and UPSERT statements ready for PostgreSQL, MySQL, SQL Server, SQLite, Oracle, or BigQuery. Column types are inferred, identifiers are quoted per dialect, large loads are batched, and a rollback DELETE plus a validation report help you review the script before running it against your database. Nothing connects to a database and nothing is uploaded — generation is fully local.
What it does
- Generates batched INSERT statements (multi-row VALUES).
- Generates UPSERT: ON CONFLICT DO UPDATE (PostgreSQL, SQLite) and INSERT … ON DUPLICATE KEY UPDATE (MySQL), plus INSERT … DO NOTHING.
- Infers column types (integer, decimal, boolean, text) and formats literals accordingly.
- Validation report: reserved-word and special-character identifiers, blank headers, leading-zero IDs, secret-like columns.
- A rollback DELETE … WHERE key IN (...) generated from the key column, to undo the load.
- Dialect-correct quoting and identifier handling for PostgreSQL, MySQL, SQL Server, SQLite, Oracle, BigQuery.
- Need a starter
CREATE TABLE? Use the CSV Viewer's Column profile, which drafts one from inferred types.
When to use it
- Load spreadsheet data into a staging or QA database without writing the SQL by hand.
- Build seed data scripts for tests or local environments.
- Generate UPSERT SQL keyed on
idoremailfor an idempotent reload. - Migrate a flat file into a table with dialect-correct INSERTs.
- Produce a reviewable change script (plus its rollback) for a DBA to run.
- Prepare a backfill batch split into manageable chunks.
How to use it
- Paste your CSV including the header row.
- Pick the SQL dialect (PostgreSQL, MySQL, SQL Server, SQLite, Oracle, BigQuery).
- Set the target table name and choose the mode: INSERT, UPSERT, or INSERT … do nothing.
- For UPSERT, specify the unique key column(s).
- Adjust batch size, boolean style, and identifier quoting as needed.
- Open the Rollback & report tab to review inferred types, identifier warnings, and the rollback DELETE.
- Copy or download the generated SQL and review it before applying.
Tips & pitfalls
- UPSERT requires a real unique or primary key constraint in your database — duplicate keys inside the CSV will repeat updates.
- NULL handling: empty CSV cells become
NULLby default — toggle "Empty → NULL" off to keep empty strings. - Leading-zero IDs (
007) lose their zeros when treated as integers; the generator keeps such columns as text and the report flags them. - Boolean inference from
true/false/1/0varies by dialect — use the Booleans option (TRUE/FALSE vs 1/0). - For very large datasets, prefer COPY (PostgreSQL) or LOAD DATA (MySQL) over generated INSERTs.
- The tool never connects to a database. The generated SQL is a script for you to review and run.
FAQ
- How do I convert CSV to SQL INSERT statements? Paste the CSV with a header row, choose your dialect and table name, and copy the generated INSERT script.
- How do I generate UPSERT SQL? Switch the mode to UPSERT and specify the unique key columns. The tool emits ON CONFLICT (PostgreSQL/SQLite) or ON DUPLICATE KEY UPDATE (MySQL).
- Does it support MERGE statements? The core emits UPSERT via ON CONFLICT / ON DUPLICATE KEY, which covers the common idempotent-load case; for SQL Server MERGE, adapt the generated UPSERT to a MERGE with matched / not-matched clauses.
- Can I generate CREATE TABLE from CSV? Yes — the CSV Viewer's Column profile drafts a
CREATE TABLEfrom inferred types you can refine. - Does it execute SQL against my database? No — the tool never connects to a database. It only generates a script for review and manual execution.
- Is my CSV uploaded? No. All generation runs in your browser.
- How does it handle types? Integer, decimal, and boolean columns are inferred and formatted as literals; everything else is quoted as text (leading-zero values are kept as text to preserve zeros).
Runs locally in your browser. No uploads. The tool generates SQL scripts but never connects to or executes against a database.