CH_20 Transaction Management in DBMS

by Jasleen Chhabra | Updated on 29 September 2024

Transaction Management in DBMS

Introduction to Transaction Management

In the world of databases, a transaction refers to a series of logically related operations that together form a single, indivisible unit of work. These operations often involve reading, updating, or writing data to ensure that a specific task is completed effectively. A classic example of a transaction is transferring money between two bank accounts. Each step in this process, such as reading balances, deducting money, and updating the accounts, is part of the transaction.


Simple Transaction Example

Consider a transaction where you’re transferring funds from your account to a friend's account. The set of operations may include the following:

  1. Reading your account balance.
  2. Deducting the transfer amount from your balance.
  3. Updating your account with the new balance.
  4. Reading your friend's account balance.
  5. Adding the transferred amount to their account.
  6. Updating your friend's account with the new balance.

This group of operations is referred to as a single transaction. If any step in the process fails, it can cause inconsistency in the database, which transaction management aims to prevent.


Transaction Failures: The Problem

The challenge with transactions is that failures can occur before all operations are complete. This can happen due to various issues, such as power failures or system crashes, leaving the database in an inconsistent state. For example, if the transaction fails after deducting the amount from your account but before adding it to your friend’s, the database becomes imbalanced, showing a deduction in one account without the corresponding credit.

How DBMS Solves Transaction Failures

Database management systems (DBMS) use two key operations to manage transactions effectively:

  • Commit: If all operations of a transaction are completed successfully, the changes are permanently stored in the database.
  • Rollback: If any operation within a transaction fails, all changes made by previous operations are undone, ensuring the database remains consistent.

Key Facts About Database Transactions

  • A transaction may or may not change the database contents.
  • Transactions are executed as a single unit, meaning they either complete fully or not at all.
  • If no updates are made and only data is retrieved, the transaction is considered read-only.
  • Successful transactions ensure the database transitions from one consistent state to another.

States of Transactions

Transactions in a DBMS go through multiple states during their execution:

  1. Active State: This is the starting phase where operations like reading and writing data are performed.
  2. Partially Committed State: After completing the transaction, the system prepares to finalize the changes.
  3. Committed State: Once all operations succeed, the transaction reaches the committed state, and changes are permanently saved.
  4. Failed State: If any part of the transaction fails or the system aborts it, the transaction enters the failed state.
  5. Terminated State: After the transaction has either committed or failed, it reaches the terminated state, where it leaves the system.

Conclusion

Transaction management is crucial to ensuring the reliability and consistency of data in any database system. The use of commit and rollback operations, combined with states like active, committed, and failed, help safeguard data integrity even in the event of failures.


FAQ

Any Questions?
Look Here.

Related Articles

CH_01 Database Management Systems (DBMS)

CH_02 DBMS Architecture

CH_03 DBMS Data Models

CH_04 Difference between DBMS and RDBMS

CH_05 DBMS Data Schemas and Data Independence

CH_06 Database Languages in DBMS

CH_07 ACID Properties in DBMS

CH_08 ER (Entity-Relationship) Diagrams in DBMS

CH_09 Cardinality in DBMS

CH_10 Keys in DBMS

CH_11 Generalization, Specialization, and Aggregation in DBMS

CH_12 Relational Model in DBMS

CH_13 Operations on Relational Model in DBMS

CH_14 Relational Algebra in DBMS

CH_15 Join Operations in DBMS

CH_16 Integrity Constraints in DBMS

CH_17 Relational Calculus in DBMS

CH_18 Anomalies in DBMS

CH_19 Normalization in DBMS

CH_21 ACID Properties in DBMS

CH_22 Concurrency Control in DBMS

CH_23 Data Backup and Recovery in DBMS

CH_24 Storage System in DBMS