A transaction is a sequence of operations performed as a single logical unit of work. Either all operations in the transaction complete successfully, or none of them are applied — the database is never left in a partial or inconsistent state.
Example: A bank transfer — debit £100 from Account A and credit £100 to Account B. Both must succeed or neither should happen.
ACID defines four properties that guarantee database transactions are processed reliably.
A transaction is treated as a single unit — either ALL operations complete (COMMIT) or NONE are applied (ROLLBACK). No partial updates.
A transaction brings the database from one valid state to another valid state. All integrity constraints (PK, FK, NOT NULL, CHECK) must remain satisfied before and after.
Concurrent transactions execute as if they were serial (one at a time). Intermediate states of a transaction are invisible to other transactions.
Once a transaction is committed, changes are permanent — even if the system crashes immediately after. Achieved via transaction logs and write-ahead logging.
When multiple transactions run simultaneously, three classic problems can arise without proper control:
| Problem | Description | Example |
|---|---|---|
| Lost Update | Two transactions read the same value and both update it — one update overwrites the other | T1 and T2 both read stock=10. T1 sets stock=8, T2 sets stock=9. T1's update is lost. |
| Dirty Read | A transaction reads data written by an uncommitted transaction that later rolls back | T1 changes balance to £500. T2 reads £500. T1 rolls back. T2 acted on invalid data. |
| Uncommitted Dependency | Same as dirty read — reading data that was never permanently written | Also called "dirty read" in some texts — reading uncommitted changes. |
Each transaction is given a unique timestamp when it starts. Operations are ordered based on timestamps — older transactions have priority. No locks needed; conflicts resolved by timestamp comparison.
Two transactions each hold a lock that the other needs — both wait indefinitely. Solutions: timeout (abort one after a wait threshold), deadlock detection graphs (abort the younger transaction).
8 questions · instantly marked · AQA 7517 standard
| Term | Definition |
|---|
10 questions · 10 minutes