Database Systems · Transactions and ACID
Transaction Concept: Single Logical Unit of Work (Bank Transfer Example)
Overview
A transaction is a collection of operations that together perform one single logical unit of work. The bank transfer example shows why a single logical request may need several database operations, and why all of them must be treated as one unit.
Key concepts
- Transaction: a collection of operations that perform a single logical unit of work.
- Single logical unit of work: one request, such as transferring money from account A to account B, even though it requires several steps.
- Bank transfer (T1): a request to transfer money from account A to account B; it is one transaction.
- Multiple operations per unit: the data for A and B is stored in the database, so the transaction must first read the required account balances before updating them.
- Reading B is necessary: B's current balance must be known before it can be incremented and written back.
Drawing the diagram…
How it works
- Read the balance of account A (value read: 100).
- Decrement A by the transfer amount, 50.
- Write the updated balance of A back to the database.
- Read the balance of account B (value read: 200).
- Add 50 to B.
- Write the updated balance of B back to the database.
All six operations together perform one single logical unit of work.
Worked examples
Transfer amount = 50 from A to B.
| Account | Initial Balance | Transfer | Final Balance |
|---|---|---|---|
| A | 100 | −50 | 50 |
| B | 200 | +50 | 250 |
Steps of transaction T1:
- Read the account balance of A → balance of A = 100.
- Decrement A by 50 → A becomes 50.
- Write the updated balance of A back → A = 50.
- Read the account balance of B → balance of B = 200.
- Add 50 to B → B becomes 250.
- Write the updated balance of B back → B = 250.
After all six operations: A has 50 and B has 250.
Revision summary
- A transaction is a collection of operations forming one single logical unit of work.
- A single logical unit of work may require multiple database operations.
- The six operations are: read A, decrement A, write A, read B, increment B, write B.
- All six operations are required to complete the single logical work of transferring money from A to B.
- The transaction must not stop after updating A; the amount must also be increased on B's side.
- B must be read before it is incremented and written back, because its current balance must be known.
Previous-year exam insights
- The basic database access operations that a transaction is built from are read_item(X) and write_item(X); every transaction is a sequence of these two primitives.
Asked inUGC NET 2011 - A transaction is a unit of both recovery and concurrency control: it must be atomic (all-or-nothing), consistent (preserve database consistency), isolated (no interference with concurrent transactions) and durable (effects survive failures) — the ACID properties.
- A transaction ends with either COMMIT (all its changes are made permanent) or ROLLBACK/ABORT (all its changes are undone), and a partially executed transaction must be rolled back so the database is never left in an inconsistent state.
- A transaction is a logical unit of work that may consist of many operations on many data items, but it is treated as a single indivisible unit by the DBMS.
- Read_item(X) copies the value of data item X from the database (disk/buffer) into the transaction's local workspace, and Write_item(X) copies the value of X from the local workspace back to the database.