sql · level 3 · unit 5 · lesson 3
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
marks a spot you can roll back to.
A long job might have one bad step among many good ones. ROLLBACK would throw away the lot. A savepoint lets you undo only part: SAVEPOINT name marks a spot inside the transaction.
undoes everything since that spot and keeps what came before. removes the mark and keeps the changes. The final COMMIT or ROLLBACK still decides for everything.
Here the arcade restocks stickers, then tries a teddy price rise. The rise is a mistake, so only that part goes.
BEGIN;
UPDATE prizes SET stock = stock + 20 WHERE prize = 'stickers';
SAVEPOINT price_rise;
UPDATE prizes SET cost = 99 WHERE prize = 'teddy';
ROLLBACK TO price_rise;
COMMIT;
SELECT prize, cost, stock FROM prizes ORDER BY prize; After ROLLBACK TO, the savepoint is still there, so you can try again from the same spot.
guess first
A released savepoint, then a full rollback. What is left?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
BEGIN;
UPDATE wallets SET tokens = tokens + 1;
SAVEPOINT bonus;
UPDATE wallets SET tokens = tokens + 100;
RELEASE bonus;
ROLLBACK;
SELECT SUM(tokens) AS total FROM wallets;
your turn
Your turn. Keep one delivery, undo the other.
Two deliveries arrive, but the teddy one is a mistake. Pick any name for the savepoint and use it in both blanks, so only the teddy delivery is undone.
result
Your answer appears here as a table.
fix it
The refund cannot find its checkpoint. Fix it!
result
Your answer appears here as a table.
- Read the error. Which savepoint can SQLite not find?
- A savepoint's name must be spelt the same way every time you use it.
- Change refnud to refund on line 4, then press run.
nailed it
you undid one step and kept the rest. :D
SAVEPOINT namemarks a spot inside a transaction.ROLLBACK TO nameundoes only the changes since that spot.RELEASEkeeps the changes, butCOMMITstill decides.
new words in your collection
- SAVEPOINT
- ROLLBACK TO
- RELEASE
This lesson isn’t saved. A free account remembers every lesson you finish.