Why this lesson matters

Understand concurrency basics 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 Concurrency Basics, the outcome to verify is: Run the statement against sample data and inspect the result before moving to the next case.
  • In Concurrency Basics, 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.
  • Concurrency Basics 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 Concurrency Basics walkthrough: Run the statement against sample data and inspect the result before moving to the next case.

example.sqlsql
BEGIN;
SELECT quantity FROM inventory WHERE product_id = 9 FOR UPDATE;
UPDATE inventory SET quantity = quantity - 1 WHERE product_id = 9;
COMMIT;

Practice it yourself

Practice

Concurrency Basics 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