Lesson 21 of 30 · Changing Data
Boss: Fix the Market Ledger with SQL INSERT, UPDATE and DELETE
The Ledger Wraith blocks the way. Every test you pass deals damage — pass them all to defeat it and claim a loot chest.
Deep in the counting-house of the market, the Ledger Wraith feeds on bad records. It has slipped phantom receipts into the books, inflated prices, cursed a name and stolen gold from the Arcane Circle. Every record you set right weakens it, so fix the whole ledger and it fades into dust.
Battle plan
This fight uses all three statements from this chapter, on the usual tables:
| Statement | Use it to |
|---|---|
INSERT INTO … (columns) VALUES (…); |
add missing rows |
UPDATE … SET column = expression WHERE …; |
correct values, also relative ones like gold = gold + 50 |
DELETE FROM … WHERE …; |
remove rows that shouldn't exist |
| Table | Columns |
|---|---|
heroes |
id, name, class, level, gold, guild_id, joined |
items |
id, name, type, price, rarity ('common', 'rare', 'epic' or 'legendary') |
purchases |
id, hero_id, item_id, quantity (default 1), bought_on |
The Wraith has already changed the data in this lesson's database, so look before you fix: SELECT * FROM items WHERE rarity = 'rare'; shows the damage. Your statements run top to bottom on the same data, and each one sees the changes made by the ones before it.
Assignment
Repair the ledger with INSERT, UPDATE and DELETE statements:
- Phantom receipts. Three purchases are signed by hero
66, and no such hero exists. Delete every purchase withhero_id66. - Inflated prices. Every
'rare'item now costs ten times its real price. Divide their prices by 10 with oneUPDATE. - A cursed name. Item
9is now called'Mana Poshun'. Rename it to'Mana Potion'. - Stolen gold. The Wraith took 50 gold from every hero of the Arcane Circle (guild
3). Give each of them 50 gold back. - A hidden item. The Wraith kept a new item off the books:
'Scroll of Banishing', type'scroll', price150, rarity'rare'. Add it and let SQLite choose its id (it becomes item 15). - A lost sale. Elara Brightwell (hero
5) bought 2 Scrolls of Banishing on'2025-06-07'. Record that purchase.
Each passing test lands a blow on the Wraith. Make all nine pass to banish it.
Premium lesson
Unlock the full Learn SQL course
- All 30 lessons, bosses and quizzes — lifetime access
- One payment of $35, no subscription
- Finish within 30 days and claim $10.50 (30%) back
Want more than one course?
The All-Access Pass unlocks all 8 courses and every new one we release, for $120 once.
Keep learning
Need a quick reminder? The SQL cheat sheet has every topic of Learn SQL on one page.
Lesson last updated on .