Adding Several Rows
One INSERT can add several rows at once. After VALUES, write a pair of parentheses for each row and separate them with commas. These are three new reviews from customers who bought the games:
INSERT INTO reviews (game_id, customer_id, stars, comment)
VALUES
(4, 4, 5, 'Hours of fun.'),
(14, 2, 4, NULL),
(17, 1, 4, 'Fast and fair.');Results then shows Rows changed: 3. All the rows share one list of columns, so each of them needs a value for each column: the second review has no comment, so it gets NULL. A comma goes between the rows, and a semicolon after the last one. Several rows in one statement are quicker to write than an INSERT for each of them, and quicker for the database to add, too.
You don't have to fill every column. A column that you leave out of the list gets NULL. Here, the review has no comment:
INSERT INTO reviews (game_id, customer_id, stars)
VALUES (20, 2, 5);
SELECT *
FROM reviews
WHERE game_id = 20;| game_id | customer_id | stars | comment |
|---|---|---|---|
| 20 | 2 | 5 | NULL |
| 20 | 4 | 4 | NULL |
That works only for columns that may be empty. Most columns of the shop's tables must have a value, and when you leave one of them out, such as stars, the database refuses the row: NOT NULL constraint failed: reviews.stars. You'll learn more about such rules soon.
The ID is a special case. A column id that the table defines as INTEGER PRIMARY KEY (all the id columns of Pixel Shop are like that) fills itself: leave it out, and SQLite gives the new row the next number, the highest ID in the table plus one. The orders go up to 30, so a new order gets 31:
INSERT INTO orders (customer_id, ordered_at, status)
VALUES (14, '2026-01-08', 'paid');
SELECT *
FROM orders
WHERE id > 28;| id | customer_id | ordered_at | status |
|---|---|---|---|
| 29 | 3 | 2025-12-12 | paid |
| 30 | 4 | 2025-12-22 | paid |
| 31 | 14 | 2026-01-08 | paid |
That's how real apps add rows: they let the database choose the ID. When you choose it yourself, it may already be taken, and the database refuses the row (UNIQUE constraint failed: orders.id). In the previous exercise, you chose the IDs only to know which rows to look for.
Typical mistake: a comma after the last row. VALUES (4, 4, 5), (14, 2, 4),; ends with the error near ";": syntax error. Between the rows, there's a comma; after the last one, only the semicolon.
Instructions
The shop has announced three new games, which haven't come out yet: Frost Giants (RPG, $55, for ages 16 and up), Pet Hotel (Simulation, $20, for ages 3 and up) and Sky Racers (Racing, $35, for ages 7 and up). Add them with one INSERT. Leave out the column id, which fills itself, and the column released, as the release dates aren't known yet.
Below it, show the ID, title, price and release date of all the games that haven't come out yet, sorted by ID. The new ones got the IDs 21 to 23, and no release date:
| id | title | price | released |
|---|---|---|---|
| 18 | Robot Rebellion | 40 | NULL |
| 19 | Mystery Manor | 25 | NULL |
| 21 | Frost Giants | 55 | NULL |
| 22 | Pet Hotel | 20 | NULL |
| 23 | Sky Racers | 35 | NULL |
Start programming for free
2/9