SQL Insert Generator
Generate MySQL, PostgreSQL or SQLite INSERT from CSV
Processed in your browser without saving input. Input: up to 1 MiB, 5,000 rows and 200 columns. SQL output: up to 4 MiB. Newlines inside quoted fields are preserved; invalid quotes or unequal record widths are rejected.
Headers are trimmed; blank headers use col_N and duplicates receive unique suffixes. Check the column mapping and target table types. Auto detection converts true/false and safe numbers; leading zeros and unsafe numbers stay text.
Generate SQL to see the result. Editing input or settings clears the previous result.
The full guide also includes pitfalls, worked examples, snippets, FAQs, and related tools for checking results or troubleshooting.
About this tool
SQL Insert Generator converts delimited text into INSERT statements for MySQL, PostgreSQL or SQLite. It checks quotation and equal record widths, preserves field newlines, and shows how trimmed, blank or duplicate headers map to unique quoted column names. Values remain text by default; optional typing converts safe numbers and booleans while retaining leading-zero identifiers and unsafe numeric tokens as text. Empty-to-NULL applies only to truly empty fields. Choose comma, semicolon, Tab or pipe and 1β1,000 rows per INSERT. Inputs are limited to 1 MiB, 5,000 rows and 200 columns. Column names use 1β63 UTF-8 bytes without control characters or outer whitespace; the table field accepts an ASCII table or schema.table. NUL and unpaired Unicode surrogates are rejected. Generation stays in the browser and input is not saved. Check the mapped columns and target table types, which can still coerce incoming values. Generated SQL is capped at 4 MiB; increase batch size or reduce input if expansion exceeds this limit. The page previews the first 64 KiB, while copy and download contain the complete accepted output.
Failure Clinic (Common Pitfalls)
Small input produces a large script
Cause: A batch size of 1 repeats the table and column list for every row; sparse JSON can expand greatly.
Fix: Increase rows per INSERT or reduce the sample. Output above 4 MiB is rejected without partial SQL. The 64 KiB preview is shorter than a large accepted script; copy and download use the full result.
A generated column name does not match the existing table
Cause: Blank headers receive col_N; duplicate names, including case variants, receive unique suffixes. Headers are trimmed.
Fix: Read the mapping before importing. Rename the source headers to match your schema, or deliberately create the mapped columns.
A string ID changes after database import
Cause: Automatic types may be enabled, or the destination column may be numeric even when SQL contains a text expression.
Fix: Keep automatic types off for identifiers and use a text column in the target table. Leading-zero and unsafe numeric tokens remain text even in automatic mode.
A pasted spreadsheet is not parsed as expected
Cause: The generator accepts delimited text, not XLSX files. The delimiter must match the input, and each logical record must have equal width.
Fix: Choose Tab for pasted tabular text or export CSV. Quote an entire field containing delimiters/newlines, and double internal quotes. Fix bad records instead of silently padding them.
Scenario Recipes
Prepare a CSV seed script without changing identifiers
Goal: Import two customer IDs while preserving leading zeros and an embedded newline.
- Choose the target dialect and existing table; paste id,note followed by 00123,"line 1<newline>line 2" and 00456,ok, replacing <newline> with a real line break.
- Keep automatic types off and empty-to-NULL off. Use a batch size of 1 and generate.
- Confirm two data rows, two INSERT statements and the displayed column mapping. In a temporary target table with text columns, execute and read back 00123, 00456 and the full first note.
Result: A dialect-specific INSERT script whose text values retain the input data. Existing column types can still coerce values.
Production Snippets
Keep IDs as text and inspect renamed columns
text
CSV:
a,a,a_2,A
00123,second,third,fourth
Header mapping:
a β a
a β a_3
a_2 β a_2
A β A_4
With automatic types off, 00123 is a text value.
The target table must contain the mapped names.
MySQL uses UTF-8 hex-to-text expressions to preserve backslashes
regardless of NO_BACKSLASH_ESCAPES.Frequently Asked Questions
Which SQL dialects are supported?
MySQL, PostgreSQL and SQLite. Choose the target before generating; string expressions and identifier quotes follow that dialect. This tool emits INSERT only and does not connect to a database.
Will 00123 keep its leading zeros?
Yes, it is emitted as text, including when automatic types are enabled. Use a text column in the target table too; a numeric destination can still change it.
How are blank or duplicate headers handled?
Headers are trimmed. Blank names become col_N and duplicate names, including case variants, receive unique suffixes reserved against all natural names. The result displays every source-to-column mapping.
What happens to empty fields, whitespace and NULL text?
Empty fields remain empty strings by default. The NULL option changes only zero-length fields; spaces remain text. Literal null and NULL remain text even with automatic types on.
Why is my CSV rejected?
Use equal field counts and valid quoted fields; internal quotes must be doubled. Choose the matching comma, semicolon, Tab or pipe delimiter. XLSX files, NUL, oversized inputs and fractional batch sizes are unsupported.
Is my data saved or uploaded?
SQL generation runs locally and does not save input drafts or contact a database. Changing input or settings clears the old result; generate again before copying or downloading.
Keep browsing