Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
What is a transaction states in DBMS?
3.
Transaction States in DBMS
4.
Different Types of Transaction States in DBMS
4.1.
Active State
4.2.
Partially Committed State
4.3.
Committed State
4.4.
Failed State
4.5.
Aborted State
4.6.
Terminated State
5.
Example of Transaction State
6.
Frequently Asked Questions
6.1.
What is a transaction in DBMS?
6.2.
What are the states of transaction in DBMS?
6.3.
What are the transaction states in distributed system?
6.4.
What are the 4 basic transactions?
6.5.
What are the 2 major types of transactions?
7.
Conclusion
Last Updated: May 9, 2024
Easy

States of Transaction in DBMS

Author Nidhi Kumari
1 upvote
Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

Understanding transaction states in Database Management Systems (DBMS) is crucial for maintaining data integrity and consistency in modern databases. Transactions play a pivotal role in ensuring that database operations are atomic, consistent, isolated, and durable (ACID). 

States of Transaction in DBMS

Various transactions are carried out to alter the data in a database. There are various states that a transaction goes through over its existence. 

This article aims to explore and examine various states of transaction in DBMS. We will cover the qualities of various states of transaction in DBMS.

What is a transaction states in DBMS?

A  transaction is a series of operations or program units performed to complete a set of logical tasks whose execution may or may not change a database's contents. A transaction is separated into states to handle different circumstances, including system failure.

Generally, we perform two operations in a transaction.

  • Read Operations: It reads data from a database, stores it in a buffer in the main memory, and exit.
     
  • Write Operations: the changed data value is returned to the database using the buffer.
     

It shall be regarded as a single transaction from the start of the execution of a set of instructions to the finish of it.

The essential commands in a translation in DBMS are as follows:

  • COMMIT: The COMMIT command is only sent when every instruction has been correctly carried out.
     
  • ROLLBACK: If anything goes wrong during the transaction, the entire outcome should be reverted as if the transaction never occurred.

Also read about, File System vs DBMS

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Transaction States in DBMS

The states of transaction in DBMS control the processes determining whether a transaction will proceed or be terminated. These states of transaction in DBMS outline the transaction's current situation and provide details on how it will be handled going forward. 

To control the process of transactions, they used to employ transaction logs. It is a record of activities taken by a Database management system that is used to ensure ACID properties in the phase of hardware crashes.

Every transaction in DBMS is a collection of two delimiters. Every transaction begins with delimiters marked begin transaction and ends with delimiters marked end transaction.

main()
{
begin transaction
} end transaction

 

Different Types of Transaction States in DBMS

  1. Active State.
     
  2. Partially Committed State.
     
  3. Committed State.
     
  4. Failed State.
     
  5. Aborted State.
     
  6. Terminated State.
six states of transaction in DBMS

Let’s discuss each one of them briefly.

Active State

It is the first stage of a transaction in DBMS. A transaction is said to be active if its instructions are being executed. One can perform operations such as INSERT or DELETE in the database, but the main memory buffer now contains all changes made by the transaction.

Partially Committed State

The transaction enters a partially committed state after the final instruction has completed execution. You might be amazed the final instruction has been completed. Then why it’s not in the Committed state? The main reason is all the changes made by transactions are still stored in the main memory buffer. That is why it is not regarded as completely committed.

Committed State

This can be considered as the completion of a transaction. All the changes stored in the buffer are transferred to the databases. In other words, all the instructions of a respective transaction are successfully completed, and changes are made in the database.

If a transaction reaches to committed state, then:

  • The modifications caused by the transaction cannot be undone.
     
  • The only option to reverse the modifications is to execute an additional transaction, which reverses operations in a different transaction.

Failed State

Suppose a transaction T is active or partially committed and experiences a failure that prevents it from continuing with the execution. Then, the transaction T is said to be in the failed state. Another reason can be the failure of the recovery system. T is considered to be in the failed state if any of the database recovery system's checks are unsuccessful.

Aborted State

Suppose any of the checks are unsuccessful and the transaction has reached a failed state. In that case, the database recovery mechanism will first try to recover the transaction and return it to its former consistent state. Otherwise, it will cancel the transaction or roll it back to restore consistency to the database.

The DBMS recovery system performs one of the two operations when a system reaches to aborted state:

  • Kill the transaction: The system will delete the transaction so it cannot affect other operations.
     
  • Re-start the transaction: The system, after some changes, again sends the operation to an active state.

Terminated State

This is the final stage of a transaction's life cycle. The transaction finally enters the terminated state when its life cycle is completed after having been in the committed or aborted stage.

Check this out :  what is schema in dbms

Example of Transaction State

  • Consider a banking application where a customer transfers money from one account to another. The transaction involves two main steps: deducting the amount from the sender's account and crediting it to the recipient's account. Let's examine the transaction states in this scenario:
  • Active State: The transaction starts in the active state when the customer initiates the transfer. It is currently executing and modifying the database.
  • Partially Committed State: After deducting the amount from the sender's account, the transaction enters the partially committed state. At this point, it has made all modifications to the database but has not yet been confirmed.
  • Committed State: Once the amount is successfully credited to the recipient's account, the transaction enters the committed state. All changes made by the transaction are now permanently saved in the database, and the transaction is considered successful.
  • Aborted State: If an error occurs during the transaction process, such as insufficient funds or a database failure, the transaction may enter the aborted state. In this state, any changes made by the transaction are rolled back, and the database returns to its original state.

Frequently Asked Questions

What is a transaction in DBMS?

A transaction is a series of operations or program units performed to complete a set of logical tasks whose execution may or may not change a database's contents. If we are performing some read-write operations on any database, it can be considered a transaction in DBMS.

What are the states of transaction in DBMS?

The states of a transaction in DBMS are:

  1. Active: Transaction is executing and modifying the database.
  2. Partially Committed: Transaction has made all modifications but not yet confirmed.
  3. Committed: Changes are permanently saved.
  4. Aborted: Transaction is rolled back due to failure.

What are the transaction states in distributed system?

In distributed systems, transaction states include: Active, Partially Committed, Committed, and Aborted. These states indicate the progress and outcome of transactions across multiple nodes or components.

What are the 4 basic transactions?

The four basic transactions are: Read, Write, Commit, and Abort. These transactions define the fundamental operations performed on data within a database management system (DBMS).

What are the 2 major types of transactions?

The two major types of transactions are: Short Transactions and Long Transactions. Short transactions are brief and typically complete quickly, while long transactions involve extended periods and complex operations, often requiring persistence mechanisms like logging.

Conclusion

In this article, we extensively discussed states of transaction in DBMS. We discussed these states of transaction in DBMS, outlined the transaction's current situation, and provided details on how it will be handled going forward. 

We hope this blog has helped you. We recommend you visit our articles on transactions in DBMS.

If you liked our article, do upvote our article and help other ninjas grow.  You can refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive Programming, and many more!

You can also consider our DBMS Course to give your career an edge over others!

Happy Reading!!

Previous article
Serializability in DBMS
Next article
Log Based recovery in DBMS
Live masterclass