Learn with Abdou

Chapter 9 · Concept 6 of 6 · Practice

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

Level 1: Watch it answered · Exercise 1 of 1

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

  1. BEGIN: from here on, nothing is final until COMMIT.
  2. INSERT the booking into lessons, then UPDATE the guest's balance: the two writes that belong together.
  3. 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.
  4. COMMIT: both writes become permanent. Query the balance again and it stays.
  1. ReviewBoth or neither, paragraph 1

Practice here is evidence for you and your instructor, never a grade. Grades live in Canvas.