How the SQL INSERT Generator works

Each non-empty line of the input is one row. It is split at the delimiter you choose; a value wrapped in single or double quotes can contain the delimiter, and a doubled quote inside it stands for one quote. Spaces around unquoted values are removed. Every row must have exactly as many values as there are columns, otherwise the line number is reported.

Unquoted values are interpreted: NULL becomes NULL, plain numbers such as 42 or -7.25 stay numbers, and true/false become 1/0 on SQL Server or TRUE/FALSE elsewhere. Everything else, and every quoted value, becomes a string literal with single quotes doubled (plus N'...' for non-ASCII text on SQL Server and escaped backslashes on MySQL). Table and column names are quoted with brackets, double quotes or backticks. The generator only writes SQL text; it does not run it.

How to use the SQL INSERT Generator

  1. Enter the table name and the column names separated by commas. If you leave Columns empty, the first line of values is used as the column names.
  2. Enter one row of values per line, separated by the delimiter you choose, or select Load example.
  3. Choose the dialect and how many rows go into each INSERT, and tick Quote every value as text if numbers and true/false should be stored as text.
  4. Select Generate INSERT, or press Ctrl + Enter (Cmd + Enter on a Mac), then copy the SQL or download it as a .sql file.

Example

With table dbo.Customers, columns Id, FullName, CreditLimit, IsActive, SQL Server and these rows:

1, Jane Smith, 2500.00, true
2, 'O''Connor, Seán', NULL, false

the generator writes:

INSERT INTO [dbo].[Customers] ([Id], [FullName], [CreditLimit], [IsActive]) VALUES (1, 'Jane Smith', 2500.00, 1);
INSERT INTO [dbo].[Customers] ([Id], [FullName], [CreditLimit], [IsActive]) VALUES (2, N'O''Connor, Seán', NULL, 0);

Common use cases

  • Adding a handful of rows to a lookup or configuration table without writing each statement by hand.
  • Preparing test data for a bug report or a unit test that needs a known database state.
  • Converting values copied from a spreadsheet (tab-separated) into INSERT statements.
  • Writing data scripts that escape apostrophes and Unicode text correctly for each database.

Common errors and how to fix them

Enter at least one row of values
Only the header row was supplied. Add a row of values beneath it, one row per INSERT statement you want.
A value that should be NULL was quoted as text
Empty cells and the literal word NULL are treated differently. Check the tool's NULL handling option so blanks become NULL rather than an empty string, or vice versa.
The statements fail with a type conversion error
The generator writes the values as given; it does not know your column types. Make sure dates use a format your database accepts and that numeric columns do not contain thousands separators.
A value containing an apostrophe breaks the statement
Single quotes inside values are escaped by the generator. If you edited the output afterwards, re-check the escaping by hand before running it.

Frequently asked questions

How are values interpreted?

An unquoted value that is a plain number stays a number, NULL becomes NULL, and true or false become the dialect's boolean (1 and 0 in SQL Server). Everything else becomes a string. Wrap a value in 'single' or "double" quotes to force it to be text, which also lets it contain the delimiter, for example 'Smith, Jane' or 'NULL'.

How do I include a quote inside a quoted value?

Double it: 'O''Connor' or "say ""hi""". Unquoted values can contain apostrophes as they are, such as O'Connor. In the SQL output every single quote is escaped for you.

What does Quote every value as text do?

It writes numbers and true/false as strings, for example '42' instead of 42. NULL is still written as NULL, and empty values follow the Empty values as NULL option.

Can I generate one INSERT with many rows?

Yes. Choose how many rows go into each statement. SQL Server allows at most 1,000 rows in one VALUES list, so larger batches are split into several statements for SQL Server.

Does the generator run the statements?

No. It only produces SQL text. It never connects to a database, and the values you type are not sent to our server.