How do you insert multiple rows in SQL Server with one query?
The other day I had a list of rows to add to a table, and I didn't want to write one INSERT per row. Here is how to insert multiple rows in SQL Server in one statement. The best way depends on where the rows are.
How to insert multiple rows in SQL Server: 5 ways
- My favorite: multi-row VALUES (simplest): use when I type a short list into a script.
- UNION ALL: use when each row needs a calculation.
- INSERT ... SELECT: use when the rows are already in a table or query.
- VALUES in a derived table: use when I type more than 1,000 rows.
- BULK INSERT: use when the rows are in a text file.
Two extras: one transaction for a script that already has one INSERT per row, and OUTPUT to get the new IDs back.

Every script uses a small Customers table. Swap in your own names. I made test data so you can try these: jump to it. Run them in order for the same IDs I show. I ran them on SQL 2022.
Multi-row VALUES for a short list
Write the column list once, then one set of parentheses per row.
INSERT INTO dbo.Customers (Name, City)
VALUES (N'Ava', N'Austin'),
(N'Ben', N'Boston'),
(N'Cara', NULL),
(N'Dev', N'Denver');
SELECT CustomerID, Name, City FROM dbo.Customers ORDER BY CustomerID;| CustomerID | Name | City |
|---|---|---|
| 1 | Ava | Austin |
| 2 | Ben | Boston |
| 3 | Cara | NULL |
| 4 | Dev | Denver |
One statement, four rows. A VALUES list can hold NULL too, as the Cara row shows.
Gotcha: a VALUES list stops at 1,000 rows
One VALUES list holds 1,000 rows at most. 1,000 rows ran. 1,001 rows failed:
Msg 10738, Level 15, State 1
The number of row value expressions in the INSERT statement exceeds the maximum allowed number of 1000 row values.The failed statement inserted nothing. Microsoft lists this limit on its table value constructor page. The fix is the derived table below.

UNION ALL for calculated rows
Each SELECT makes one row, and UNION ALL stacks them. Good when each row is built from expressions.
INSERT INTO dbo.Customers (Name, City)
SELECT N'Eli', N'Erie'
UNION ALL SELECT N'Fay', N'Fresno'
UNION ALL SELECT N'Gus', NULL;
SELECT CustomerID, Name, City FROM dbo.Customers
WHERE Name IN (N'Eli', N'Fay', N'Gus') ORDER BY CustomerID;| CustomerID | Name | City |
|---|---|---|
| 5 | Eli | Erie |
| 6 | Fay | Fresno |
| 7 | Gus | NULL |
Same result as the VALUES list. A long UNION ALL chain is hard to read, so I save it for calculated rows.
INSERT ... SELECT from another table
Copy rows that already exist, like a load from a staging table or an archive job.
INSERT INTO dbo.CustomersArchive (CustomerID, Name, City)
SELECT CustomerID, Name, City
FROM dbo.Customers
WHERE Name IN (N'Ava', N'Ben', N'Cara', N'Dev');
SELECT CustomerID, Name, City FROM dbo.CustomersArchive ORDER BY CustomerID;| CustomerID | Name | City |
|---|---|---|
| 1 | Ava | Austin |
| 2 | Ben | Boston |
| 3 | Cara | NULL |
| 4 | Dev | Denver |
Any SELECT works here: joins, filters, aggregates. Run the SELECT alone first and check the rows.
VALUES in a derived table for 1,000+ rows
Put the VALUES list inside a derived table and select from it. A derived table has no 1,000 row limit. I tested it with 1,500 rows.
INSERT INTO dbo.Big (Name)
SELECT v.Name
FROM (VALUES (N'Row1'), (N'Row2'), (N'Row3') /* ... 1,500 rows ... */) AS v(Name);
SELECT N'dbo.Big' AS table_name, COUNT(*) AS row_count FROM dbo.Big;| table_name | row_count |
|---|---|
| dbo.Big | 1500 |
The list above is shortened. My test list had 1,500 rows, built with code. If your rows are in a file, use the next way.
BULK INSERT from a file
Here is a small file named new_customers.csv:
Name,City
Pam,Provo
Quinn,Quincy
Ray,RenoBULK INSERT dbo.Imported
FROM 'C:\temp\new_customers.csv'
WITH (FIELDTERMINATOR = ',', ROWTERMINATOR = '0x0a', FIRSTROW = 2);
SELECT Name, City FROM dbo.Imported ORDER BY Name;| Name | City |
|---|---|
| Pam | Provo |
| Quinn | Quincy |
| Ray | Reno |
FIRSTROW = 2 skips the header line. The path must work from the machine where SQL Server runs, as the BULK INSERT page says. My test file ends each line with a line feed, so I set ROWTERMINATOR = '0x0a'. Check which line ending your file uses.
One transaction for a script with one INSERT per row
Don't want to rewrite a script with one INSERT per row? Wrap it in a transaction. COMMIT saves the three rows together.
BEGIN TRANSACTION;
INSERT INTO dbo.Log1 (Msg) VALUES (N'one');
INSERT INTO dbo.Log1 (Msg) VALUES (N'two');
INSERT INTO dbo.Log1 (Msg) VALUES (N'three');
COMMIT TRANSACTION;
SELECT N'dbo.Log1' AS table_name, COUNT(*) AS row_count FROM dbo.Log1;| table_name | row_count |
|---|---|
| dbo.Log1 | 3 |
OUTPUT to get the new IDs
The table has an IDENTITY column and you need the new IDs. SCOPE_IDENTITY() returns only the last one:
INSERT INTO dbo.Customers (Name, City)
VALUES (N'Hal', N'Hull'), (N'Ida', N'Irvine'), (N'Jon', N'Jackson');
SELECT SCOPE_IDENTITY() AS last_identity_only, @@ROWCOUNT AS rows_inserted;| last_identity_only | rows_inserted |
|---|---|
| 10 | 3 |
OUTPUT returns every new ID in the same statement:
INSERT INTO dbo.Customers (Name, City)
OUTPUT inserted.CustomerID, inserted.Name
VALUES (N'Kim', N'Kent'), (N'Lee', N'Lima'), (N'Max', N'Miami');| CustomerID | Name |
|---|---|
| 11 | Kim |
| 12 | Lee |
| 13 | Max |
To use the IDs later, send them into a table variable with OUTPUT ... INTO:
DECLARE @new TABLE (CustomerID int, Name nvarchar(50));
INSERT INTO dbo.Customers (Name, City)
OUTPUT inserted.CustomerID, inserted.Name INTO @new
VALUES (N'Ned', N'Nome'), (N'Ola', N'Omaha');
SELECT CustomerID, Name FROM @new ORDER BY CustomerID;| CustomerID | Name |
|---|---|
| 14 | Ned |
| 15 | Ola |
Gotcha: one bad row fails the whole statement
A multi-row INSERT is one statement, so it is all or nothing. Here the second row breaks the NOT NULL rule on Name:
INSERT INTO dbo.Customers (Name, City)
VALUES (N'Good1', N'X'),
(NULL, N'Y'),
(N'Good2', N'Z');Msg 515, Level 16, State 2
Cannot insert the value NULL into column 'Name', table 'dbo.Customers'; column does not allow nulls. INSERT fails.
The statement has been terminated.Afterward Customers still held 15 rows, and none was named Good1 or Good2. To load the good rows anyway, filter out the bad ones with a SELECT first (the INSERT ... SELECT way).
Check before you run
- Name the columns in the INSERT, so a new column does not break the script.
- Run the SELECT part alone first and look at the rows.
- Compare "rows affected" with the number you expected.
- Past 1,000 typed rows, use a derived table or a file.
- Add
OUTPUTwhen you need the new IDs.
Try it on my test data
Run this in a test DB, not in production. City allows NULL. Name does not. Then run the scripts above in order for the same results.
CREATE DATABASE Red9Test_insrows;
GO
USE Red9Test_insrows;
GO
CREATE TABLE dbo.Customers
(
CustomerID int IDENTITY(1,1) PRIMARY KEY,
Name nvarchar(50) NOT NULL,
City nvarchar(50) NULL
);
CREATE TABLE dbo.CustomersArchive
(
CustomerID int NOT NULL PRIMARY KEY,
Name nvarchar(50) NOT NULL,
City nvarchar(50) NULL
);
CREATE TABLE dbo.Big (Name nvarchar(50) NOT NULL);
CREATE TABLE dbo.Log1 (Msg nvarchar(50) NOT NULL);
CREATE TABLE dbo.Imported (Name nvarchar(50) NOT NULL, City nvarchar(50) NULL);For the BULK INSERT script, save the three-row CSV from above where SQL Server can read it. When you are done, drop the test DB.



