×

sql · level 3 · unit 5 · lesson 1

  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

A makes several changes count as one.

Ava gives Leo 5 arcade tokens. That is two changes: take 5 from Ava, then add 5 to Leo. If the power cut out between them, 5 tokens would vanish. Real systems cannot allow that.

Wrap the changes in a transaction. starts it, and the changes after it are held back. then makes them all permanent together. The transaction is : it happens completely or not at all.

If anything fails before COMMIT, none of the changes stick. Banks, shops and games all move value this way.

BEGIN;
UPDATE wallets SET tokens = tokens - 5 WHERE owner = 'Ava';
UPDATE wallets SET tokens = tokens + 5 WHERE owner = 'Leo';
COMMIT;

SELECT owner, tokens FROM wallets ORDER BY owner;

Other people using the database never see the halfway point, only the finished change.