Databases & Data Storage

Transaction

Definition

A database transaction is a single unit of work. It is a sequence of operations performed as a single logical unit of work. A transaction must be "all or nothing": either all of its operations are executed, or none of them are.

Why It Matters

Transactions are essential for maintaining data integrity. They allow you to perform multiple related operations and ensure that the database is always left in a consistent state, even if errors occur halfway through.

Contextual Example

Booking a flight involves several steps: checking for an available seat, reserving it, and processing the payment. These steps should be wrapped in a single transaction. If the payment fails, the seat reservation should be automatically rolled back.

Common Misunderstandings

  • A transaction is typically started with a `BEGIN TRANSACTION` command and ended with either `COMMIT` (to make the changes permanent) or `ROLLBACK` (to undo the changes).
  • The properties of reliable transactions are described by the acronym ACID.

Related Terms

Last Updated: December 17, 2025