The error does not undo the first write
BEGIN, COMMIT, ROLLBACK (desktop) · level 1 of 6
Opening your saved work…
Sign in to save across devices → · Download your guest work before switching accounts.
The error does not undo the first write · BEGIN, COMMIT, ROLLBACK (desktop) · level 1 of 6
One booking, one debit, one decision
At Harbor Snow a coaching booking is an insert and a balance debit that must land together. Read the transaction, then run it in the desktop shell on a fresh copy from the kit.
This one runs in desktop SQLite 3.25 or newer, not in the browser. Download the kit
PRAGMA foreign_keys = ON;
BEGIN;
INSERT INTO lessons VALUES (5, 1, 3, '2026-03-10', 60);
UPDATE guests SET balance = balance - 60 WHERE id = 1;
SELECT changes() AS guests_debited;
SELECT id, balance FROM guests WHERE id = 1;
COMMIT;
SELECT id, balance FROM guests WHERE id = 1;Why it works, clause by clause
- BEGIN: from here on, nothing is final until COMMIT.
- INSERT the booking into lessons, then UPDATE the guest's balance: the two writes that belong together.
- SELECT changes(): 1 means the debit touched one guest. A 0 here is the signal to ROLLBACK, because a booking nobody paid for is pending.
- COMMIT: both writes become permanent. Query the balance again and it stays.
Practice here is evidence for you and your instructor, never a grade. Grades live in Canvas.