Why this lesson matters

Understand commit and rollback and reason about it with a concrete relational example. Transactions make a group of statements succeed or fail as one unit. COMMIT publishes the work, ROLLBACK discards it, and concurrency controls protect overlapping transactions from corrupting shared state.

How to reason about it

  • For COMMIT and ROLLBACK, the outcome to verify is: Run the statement against sample data and inspect the result before moving to the next case.
  • In COMMIT and ROLLBACK, keep this failure controlled: Reading a value and updating it later without an appropriate transaction or lock can lose updates when two sessions act concurrently.
  • COMMIT and ROLLBACK practice target: Transfer a value between two rows inside one transaction, force an error to test rollback, then simulate a concurrent update with row locking.

Practical walkthrough

In the COMMIT and ROLLBACK walkthrough: Run the statement against sample data and inspect the result before moving to the next case.

example.sqlsql
BEGIN;
UPDATE inventory SET quantity = quantity - 1 WHERE product_id = 9;
-- COMMIT when all checks pass; otherwise ROLLBACK;
ROLLBACK;

Practice it yourself

Practice

COMMIT and ROLLBACK exercise

Transfer a value between two rows inside one transaction, force an error to test rollback, then simulate a concurrent update with row locking.

  • Record the expected result before execution
  • Test one valid path and one lesson-specific failure path
  • Explain in two lines which boundary owns the decision

Summary