×

sql · level 3 · unit 5 · lesson 2

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. 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.