Adding Rows with INSERT
So far, your queries have only read the data: whatever you asked, the tables stayed the same. But a shop's data changes all the time. New customers join, prices go up and down, orders come in. In this lesson, you'll learn the statements that change data: INSERT adds rows, UPDATE changes them and DELETE deletes them.
A new row is added with INSERT INTO. This statement adds a new game to the shop:
INSERT INTO games (id, title, genre, price, released, age_rating)
VALUES (21, 'Snow Patrol', 'Action', 20, '2026-03-12', 12);After INSERT INTO comes the table and, in parentheses, the columns you're filling. After VALUES come the values, in parentheses too and in the same order: the first value goes into the first column, the second value into the second column, and so on. Text and dates go in single quotes and numbers without them, just as in WHERE. And NULL means no value, as always.
An INSERT doesn't find any rows, so it has no result table. Instead, Results shows how many rows it changed: Rows changed: 1. To see the new row, query it in the same file, below the INSERT:
SELECT *
FROM games
WHERE id = 21;| id | title | genre | price | released | age_rating |
|---|---|---|---|---|---|
| 21 | Snow Patrol | Action | 20 | 2026-03-12 | 12 |
Every Run starts with a fresh copy of the database. The INSERT adds Snow Patrol, the query below it shows the game, and when you click Run again, the database is back as it was at the start, and the INSERT adds the game once more. So in this course, you can't break anything: experiment as much as you like. It also means that the statements that change data and the queries that show the change must be in the same file. The Tables tab always shows the tables as they are at the start, before your statements run. (In a real database, a change stays for good. That's why this lesson also teaches you to be careful.)
You can leave out the list of columns: INSERT INTO games VALUES (21, 'Snow Patrol', …); then needs a value for every column of the table, in the order in which the table has them. Programmers avoid that. The statement is harder to read (which number is the price, and which is the age?), and when the table gets a new column one day, it stops working. Always list the columns.
Typical mistake: values that don't match the columns. When there are more or fewer values than columns, SQLite says so, for example 4 values for 3 columns. Values in the wrong order are worse: with (price, age_rating) and VALUES (12, 20), the game costs $12 and is for ages 20 and up, and no error tells you. Check that each value is under its column.
Instructions
A new customer has just joined the shop: Ruby Ward from Leeds, with the email ruby.ward@mail.com. She joined on 2026-01-12, and Noah Wilson, the customer with ID 4, recommended the shop to her. Add her to the table customers with the ID 15. List all six columns in the INSERT.
Below the INSERT, show all the columns of the customers whose ID is greater than 12, sorted by ID. The last row is Ruby:
| id | name | city | joined | referred_by | |
|---|---|---|---|---|---|
| 13 | Sophie Adams | sophie.adams@mail.com | Manchester | 2025-08-21 | 11 |
| 14 | Max Baker | max.baker@mail.com | Bristol | 2025-10-03 | NULL |
| 15 | Ruby Ward | ruby.ward@mail.com | Leeds | 2026-01-12 | 4 |
The shop will also sell a new game: Pirate's Cove, an adventure game for $25 for ages 12 and up, which comes out on 2026-04-03. Add it with the ID 21 (mind the apostrophe in the title). Then show the title, price and release date of all the adventure games (genre Adventure), sorted by title:
| title | price | released |
|---|---|---|
| Lost Temple | 20 | 2022-04-07 |
| Mystery Manor | 25 | NULL |
| Ocean Deep | 15 | 2021-08-30 |
| Pirate's Cove | 25 | 2026-04-03 |
Start programming for free
1/9