1. Gyanastra
  2. Database Systems
  3. Transactions and ACID
  4. Transaction Concept: Single Logical Unit of Work (Bank Transfer Example)
Free lesson, no account needed 3 min read 3 practice questions after it
Asked in past papers1 time
  • UGC NET2011

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.
Figure. All six operations form one single logical unit of work. A goes from 100 to 50 and B from 200 to 250, and B must be read before it is incremented and written back.

How it works

  1. Read the balance of account A (value read: 100).
  2. Decrement A by the transfer amount, 50.
  3. Write the updated balance of A back to the database.
  4. Read the balance of account B (value read: 200).
  5. Add 50 to B.
  6. 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.

AccountInitial BalanceTransferFinal Balance
A100−5050
B200+50250

Steps of transaction T1:

  1. Read the account balance of A → balance of A = 100.
  2. Decrement A by 50 → A becomes 50.
  3. Write the updated balance of A back → A = 50.
  4. Read the account balance of B → balance of B = 200.
  5. Add 50 to B → B becomes 250.
  6. 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.
Pages 1–2 of 2