sql · level 3 · unit 5 · lesson 2
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
throws away every change since BEGIN.
Sometimes you start a change and then spot a problem: the wrong price, the wrong player, a total that looks odd. Instead of COMMIT, write ROLLBACK. Every change since BEGIN disappears, as if it never happened.
A good habit for risky jobs: BEGIN, make the change, check it with a SELECT, then COMMIT if it looks right or ROLLBACK if it does not.
ROLLBACK needs a transaction to undo. Without one, each change was saved the moment it ran.
BEGIN;
UPDATE prizes SET cost = cost * 10;
SELECT prize, cost FROM prizes ORDER BY prize;
ROLLBACK;
SELECT prize, cost FROM prizes ORDER BY prize; Prices ten times too high? The check caught it, and ROLLBACK put them back.
guess first
A big delete, then a change of heart. How many wallets?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
BEGIN;
DELETE FROM wallets WHERE tokens < 10;
ROLLBACK;
SELECT COUNT(*) AS wallets FROM wallets;
your turn
Your turn. Check, then decide.
Everyone gets a 5-token bonus inside a transaction, and the first query shows the new total. Now you decide: keep the bonus or throw it away. Fill the blank with your choice.
result
Your answer appears here as a table.
fix it
The teddy sold out by mistake, and the undo fails. Fix it!
result
Your answer appears here as a table.
- Read the error. Is a transaction running when
ROLLBACKarrives? - Without
BEGIN, the update was saved the moment it ran, so there is nothing to undo. - Add BEGIN; as a new first line, then press run.
nailed it
you can take it all back now. :D
ROLLBACKthrows away every change sinceBEGIN.- Check inside the transaction, then
COMMITorROLLBACK. - No
BEGINmeans nothing to roll back.
new words in your collection
- ROLLBACK
This lesson isn’t saved. A free account remembers every lesson you finish.