Skip to content
C

Transaction Boundaries


Transaction Boundaries

Definition

Transaction boundaries are the explicit start and end points of a transaction — where it begins (BEGIN/START TRANSACTION) and where it ends, either successfully (COMMIT) or unsuccessfully (ROLLBACK).

How It Works

sql
START TRANSACTION; -- boundary: start UPDATE accounts SET balance = balance - 200 WHERE id = 1; UPDATE accounts SET balance = balance + 200 WHERE id = 2; COMMIT; -- boundary: successful end

Everything between START TRANSACTION and COMMIT/ROLLBACK is inside the transaction's boundary — a single logical unit. Under autocommit mode (22.12), every individual statement has its OWN implicit boundary (start and commit happen automatically around each statement) unless an explicit START TRANSACTION overrides that default.

Edge Cases and Pitfalls

  • Forgetting the closing boundary (COMMIT/ROLLBACK) leaves a transaction OPEN indefinitely — holding locks and blocking other work (as covered in 11.11) — a genuinely common operational mistake, especially in interactive database sessions where someone runs START TRANSACTION, gets distracted, and never finishes it.
  • Some dialects auto-commit a transaction implicitly when a DDL statement (CREATE TABLE, etc.) is executed inside it — meaning a boundary can end EARLIER than the explicit COMMIT/ROLLBACK you wrote, without warning (this connects back to Chapter 9's note that DDL auto-commits on most engines).
  • Nesting START TRANSACTION inside an already-open transaction behaves differently across dialects — some implicitly commit the first transaction before starting a "new" one, rather than truly nesting (see 22.13).

Key Takeaways

  • Transaction boundaries are the explicit start (BEGIN/START TRANSACTION) and end (COMMIT/ROLLBACK) points marking one logical unit.
  • Autocommit gives every statement an implicit boundary unless explicitly overridden.
  • Forgetting to close a boundary leaves a transaction open, risking held locks — a genuinely common real mistake.

Mock Test

  • Transaction Boundaries - Quick Test

    8 questions on Transaction Boundaries.

    8 questions · 8 min · Medium
    Start Mock Test