MOO WebTech
Transactionslessonadvanced

Transaction Control Language (TCL)

BEGIN, COMMIT, ROLLBACK, SAVEPOINT, ACID properties, and isolation levels.

80 minL50

Overview

This lesson covers how PostgreSQL handles transactions. Students learn the ACID properties, how to explicitly control transaction boundaries, use savepoints for partial rollback, and understand isolation levels and their practical implications.

Lesson Plan

TimeActivity
0–10 minIntro: what is a transaction? Why do we need them?
10–25 minBEGIN, COMMIT, ROLLBACK — basic transaction control
25–40 minACID properties: Atomicity, Consistency, Isolation, Durability
40–55 minSAVEPOINT and ROLLBACK TO SAVEPOINT
55–70 minIsolation levels: Read Committed, Repeatable Read, Serializable
70–80 minWrap-up: real-world transaction patterns

Key Concepts

  • BEGIN starts a transaction block; COMMIT saves, ROLLBACK undoes
  • Atomicity: all-or-nothing — partial failure rolls back everything
  • Consistency: DB moves from one valid state to another
  • Isolation: transactions don't interfere with each other
  • Durability: committed data survives crashes
  • SAVEPOINT sp1 and ROLLBACK TO sp1 for nested checkpoints
  • Default isolation in PostgreSQL: Read Committed

✏️Practice

Short in-class exercises:

  1. Demonstrate a transaction that transfers money between two accounts — rollback on error.
  2. Use a savepoint to partially undo part of a multi-step insert operation.
  3. Observe the effect of different isolation levels on concurrent reads.