A transaction represents a real-life event that work as a single unit of work. Each transaction is a set of database operations such as read, write, and update.
Examples of transaction:
Sending Rs 1000 from A’s account to B’s account.
Withdrawing cash from ATM.
Buy movie ticket online.
All of these can be broken down into database operations.
Transaction State
The transaction goes through 6 different states. The list of states given below.
Active State – The first state of transaction to begin a transaction and complete all operations except the last one.
Pre-Committed State – The state at which last operation is completed, but changes are stored in a buffer memory, not on disk.
Committed State – All changes committed to disk and stored permanently.
Failed State – If failure occur during Active state or Pre-committed state due to software or a hardware failure. Transaction enters failed state.
Abort State – All changes made are rolled back to bring database to a consistent state.
Terminated state – Transaction has nothing more to do, it is removed from the system.
Figure 1 – Transaction State Diagram
ACID Properties in DBMS
ACID properties ensures that database transactions are reliable, accurate, and fail safe.
A transaction could fail anytime and database will go to an inconsistent state.
A transaction can fail due to :
Power failure
System crash
Conflict in transactions during concurrent access.
Partial execution of transactions.
The ACID properties ensure that database transactions follow strict rules to stay consistent.
Atomicity – Transaction should complete or do nothing at all.
Consistency – Transaction should start with a consistent database and leave database consistent.
Isolation – Each transaction should run in isolation as if it is the only transaction. This will ensure that there is no conflict among concurrent transactions.
Durability – Once transaction is committed, the changes are permanent. No system failure can erase it.
SQL and Transaction Processing
In SQL , there are three commands for transaction processing;
BEGIN or BEGIN TRANSACTION
COMMIT
ROLLBACK
Transaction Logs
Transaction logs work with buffer and keep all the changes from transaction.
It help database to recover quickly using a checkpoint.
The transaction log contains
Transaction ID
Operation Records
Undo/Redo Information
Long Sequence Number (LSN)
Commit or Rollback Records
Checkpoint Records
Multiple Choice Questions
Q1. Which ACID property ensures that a transaction is either fully completed or not executed at all?
Correct Answer: Atomicity
Atomicity ensures that all operations of a transaction are executed completely or none are executed.
Q2. Which ACID property ensures that database constraints are not violated?
Correct Answer: Consistency
Consistency ensures that the database moves from one valid state to another.
Q3. Which problem is prevented by the Isolation property?
Correct Answer: Changes persist after commit
Durability guarantees that committed changes are not lost even after failures.
Q5. ACID properties are mainly required to ensure:
Correct Answer: Data reliability
ACID properties ensure correctness and reliability of transactions.
Short Questions
Q1. Define Atomicity in DBMS.
Answer:
Atomicity ensures that a transaction is treated as a single unit of work,
which means either all operations of the transaction are executed or none are executed.
Q2. Why is Isolation required in transaction processing?
Answer:
Isolation is required to ensure that concurrent transactions do not interfere
with each other and the intermediate results of one transaction are not visible to others.
Q3. What is the role of Durability in DBMS?
Answer:
Durability guarantees that once a transaction is committed,
its changes are permanently stored in the database even in the case of system failure.
Exam-Ready Revision PDF
This article covers the key concepts and practice questions.
For a structured, exam-focused revision with: