INSERT Multiple Rows
Insert many rows in a single statement by listing several value lists separated by commas.
Adding a whole IPL squad one INSERT at a time is slow and repetitive. SQL lets you add many rows in one statement — just keep adding value lists.
Definition
A multi-row INSERT adds several new rows with a single INSERT statement by supplying multiple value lists after one VALUES keyword, separated by commas. Each value list (in brackets) becomes one row.
- One statement — one
INSERT INTO, oneVALUES. - Multiple value lists —
(…), (…), (…). - All or nothing — if any one row breaks a rule (duplicate key, NULL in a NOT NULL column), the whole statement fails and none of the rows are added.
Syntax
sql
INSERT INTO table_name (column1, column2, ...)
VALUES
(value1, value2, ...), -- row 1
(value1, value2, ...), -- row 2
(value1, value2, ...); -- row 3 (no comma after the last one)From the course slide:
sql
INSERT INTO players (id, name, team, country, runs)
VALUES (1, 'Virat Kohli', 'RCB', 'India', 750),
(2, 'Rohit Sharma', 'MI', 'India', 500);Multiple inserts: just add another list of values.
Example — 5 new rows at once
Before: the table has only Virat Kohli.
| id | name | team | country | runs |
|---|---|---|---|---|
| 1 | Virat Kohli | RCB | India | 750 |
sql
INSERT INTO players VALUES
(2, 'Rohit Sharma', 'MI', 'India', 500),
(3, 'Jos Buttler', 'RR', 'England', 850),
(4, 'MS Dhoni', 'CSK', 'India', 350),
(5, 'David Warner', 'DC', 'Australia', 700),
(6, 'Jasprit Bumrah', 'MI', 'India', 20);
SELECT * FROM players;After — 5 new rows at once:
| id | name | team | country | runs |
|---|---|---|---|---|
| 1 | Virat Kohli | RCB | India | 750 |
| 2 | Rohit Sharma | MI | India | 500 |
| 3 | Jos Buttler | RR | England | 850 |
| 4 | MS Dhoni | CSK | India | 350 |
| 5 | David Warner | DC | Australia | 700 |
| 6 | Jasprit Bumrah | MI | India | 20 |
Step by step: 1️⃣ One INSERT, many rows → 2️⃣ separate the value lists with commas. SQL Server reports (5 rows affected).
Note: This example has no column list, so we must give a value for EVERY column, in table order (
id, name, team, country, runs). It works, but writing the column list is still the safer habit.
Why multi-row is better than many single INSERTs
| Many single INSERTs | One multi-row INSERT |
|---|---|
INSERT … VALUES (2, …); ×5 | INSERT … VALUES (2, …), (3, …), …; |
| 5 statements, 5 round-trips | 1 statement — shorter and faster |
| A failure in row 4 leaves rows 2–3 inserted | All-or-nothing — no half-finished data |
Common mistakes
- ❌ Writing
VALUESbefore every row:VALUES (…), VALUES (…). ✅VALUESappears once. - ❌ Forgetting the comma between rows, or leaving one after the last row. ✅
(…),(…),(…); - ❌ Rows with different numbers of values. ✅ Every list must match the column list.
- ❌ One duplicate id in the batch and expecting the others to be saved. ✅ The whole statement is rejected — fix the duplicate and re-run.
SQL Server vs MySQL / PostgreSQL
All three support multi-row VALUES. In SQL Server a single VALUES list may contain at most 1,000 rows — for more, use several INSERTs, INSERT … SELECT, or bulk-load tools (BULK INSERT, bcp).
Interview tip
Q: If one of the rows in a multi-row INSERT violates the primary key, how many rows are inserted? A: Zero. A single INSERT statement is atomic — it succeeds completely or fails completely.
Key points to remember
- One INSERT can add many rows: write one VALUES, then several value lists separated by commas.
- Each bracketed value list becomes one new row.
- Without a column list, every row must give values for ALL columns in table order.
- A multi-row INSERT is all-or-nothing: if one row fails, no rows are inserted.
- It's shorter and faster than many single-row INSERTs.
- SQL Server allows at most 1,000 rows in one VALUES list.
Try it yourself
Add 5 rows with one INSERT
This example runs a small setup step first — click to see it
DELETE FROM players WHERE id > 1;
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
Multi-row INSERT with a column list
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
All or nothing: one bad row stops the batch
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
Practice: add three bowlers
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
Revision Flashcards
Tap a card to flip it and see the answer.
