About the SQL INSERT Generator
This SQL INSERT generator turns CSV data into INSERT statements you can paste straight into a database client or migration file. Paste rows exported from Excel, Google Sheets or another database, name the target table and choose your database: identifiers are quoted the right way for MySQL (backticks), PostgreSQL, SQLite and standard SQL (double quotes) or SQL Server (square brackets), and text values are escaped so apostrophes and backslashes cannot break the statement.
It is built for developers seeding test data, analysts loading a one-off spreadsheet, and anyone migrating a small table between systems without setting up an import job. Choose one INSERT per row, or multi-row INSERTs batched to a size your database accepts, and optionally generate a CREATE TABLE statement with column types inferred from the data.
Columns where every value is a plain number are written unquoted; any column containing text, or numbers with leading zeros like ZIP codes, is quoted in full. Empty cells and the word NULL become SQL NULL. The CSV parser follows RFC 4180, so quoted fields with commas, line breaks and doubled quotes are handled.
How to use the sql insert generator
- 1Paste your CSV, including the header row if it has one.
- 2Enter the table name and choose your database.
- 3Pick multi-row or one INSERT per row, and the batch size for large files.
- 4Optionally add a CREATE TABLE statement with inferred column types.
- 5Copy the SQL and run it in your database client or migration.
Formula and method
The CSV is parsed according to RFC 4180: fields may be wrapped in double quotes, a doubled quote inside a quoted field is a literal quote, and quoted fields can contain delimiters and line breaks. With the header option on, the first row supplies the column names, which are quoted with the identifier style of the chosen database.
Each column is then classified from its non-empty values: integers only, decimals, scientific notation, ISO dates (YYYY-MM-DD) or text. Numeric columns are written as bare numbers; everything else becomes a string literal in single quotes with any single quote doubled (the SQL standard escape), and for MySQL backslashes are doubled too. Empty cells and the literal word NULL become SQL NULL. In multi-row mode the rows are grouped into INSERT statements of the chosen batch size.
Worked examples
Customers CSV to PostgreSQL
id and balance contain only numbers, so they are unquoted. The apostrophe in O’Neil is escaped by doubling it, the CSV-escaped quotes around puzzles become plain double quotes inside the SQL string, and the empty notes cell becomes NULL. All three rows go into one multi-row INSERT.
One statement per row for MySQL
The semicolon delimiter is detected automatically. SKUs with leading zeros stay quoted so 00123 is not turned into 123, qty is numeric, and backslashes in the paths are doubled because MySQL treats a single backslash as an escape character. schema.table is quoted part by part.
With CREATE TABLE for SQL Server
The longest code is 3 characters, so it becomes NVARCHAR(3). Prices need up to 3 digits before the point and 2 after, giving DECIMAL(5,2). Both launch values are ISO dates, so the column is typed DATE while the values are written as quoted strings, which SQL Server converts on insert.
Frequently asked questions
How do I escape an apostrophe in a SQL INSERT?+
Double it: O'Neil is written 'O''Neil'. This is the SQL standard escape and works in every major database. MySQL also accepts \' by default, which is why this tool doubles backslashes for MySQL so that a path like C:\temp is stored correctly.
Is a multi-row INSERT faster than one INSERT per row?+
Usually, yes. A single statement with many rows means fewer round trips and less parsing and transaction overhead. Very large statements can hit limits, though — SQL Server allows 1,000 rows per VALUES list and MySQL is limited by max_allowed_packet — so batch big files.
How are NULL values handled?+
Empty cells become SQL NULL when the option is on, and a cell containing just the word NULL (any case) is always treated as NULL. Turn the option off to insert empty strings instead, which matters for NOT NULL text columns.
Why are some numbers quoted?+
A column is only written as numbers when every value in it is a plain number. If any value has a leading zero (like a ZIP code or SKU), a currency symbol, a thousands separator or text, the whole column is quoted so no value is silently changed.
Should I use INSERT statements or a bulk loader for big files?+
For thousands of rows, INSERT statements are convenient. For hundreds of thousands or more, native bulk loaders such as PostgreSQL COPY, MySQL LOAD DATA INFILE or SQL Server BULK INSERT are much faster and use less memory.