A Transaction in DBMS is a sequence of one or more SQL operations that are executed as a single logical unit of work. A transaction must either be fully completed or not executed at all. It ensures that the database remains consistent even in the presence of errors, system failures, or concurrent access.
Typical operations inside a transaction include:
INSERT
UPDATE
DELETE
For example, transferring money between two bank accounts involves:
Deducting amount from Account A
Adding amount to Account B
These steps must be treated as a single transaction.
The four ACID properties guarantee reliability and consistency.
All or nothing property
Ensures entire transaction is completed.
If any part fails, the whole transaction is rolled back.
Example:
If money is deducted from Account A but not added to B, entire transaction must be cancelled.
Transaction must take the database from one valid state to another valid state.
Ensures rules, constraints, and triggers are not violated.
Multiple transactions can occur at the same time without interfering with each other.
Intermediate results of one transaction should be hidden from others.
Example:
Two users withdrawing money simultaneously should not see inconsistent balance.
Once a transaction is committed, its changes are permanent—even if system crashes.
DBMS stores changes to non-volatile memory.
Transaction States
A transaction passes through several states:
Active – Execution in progress
Partially Committed – Final statement executed
Committed – Successful completion, changes saved
Failed – Error or system failure
Aborted – Transaction rolled back
Terminated – Transaction completed (either committed or aborted)
Control Commands Used in Transactions
Saves all changes permanently.
Undo changes made in the current transaction.
Creates a checkpoint inside a transaction.
Transactions help avoid anomalies in concurrent environments:
Reading uncommitted data from another transaction.
Two transactions overwrite each other's data.
Data changes during a transaction when read multiple times.
New rows appear in the result of a repeated query.
Transactions execute one after another.
Safe but slow.
Transactions interleave.
Efficient but require checks for consistency.
Maintain data consistency
Provide fault tolerance
Handle system crashes safely
Ensure reliable multi-user access
Prevent data corruption
Transactions are a fundamental concept in DBMS to ensure data reliability and integrity. Using ACID properties, transactions make sure that even in the presence of system failures, power outages, or concurrent users, the database remains stable, consistent, and correct. They are essential for applications such as banking, e-commerce, reservation systems, and any real-time multi-user environment.
Take quizzes related to this topic and see where you stand!
Start Quiz Now