State of transaction in DBMS

Learn via video course
FREE
View all courses
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
Topics Covered

What is a Transaction in DBMS?

A transaction can be viewed as a set of operations used to perform a logical set of tasks. Transactions are used to change data in the database. This can be done by inserting new data, modifying existing data, or deleting existing data.

What are the Transaction States in DBMS?

The different stages a transaction goes through during its lifecycle are known as the transaction states. The following is a diagrammatic representation of the different stages of a transaction.

transaction-state-in-dbms1

What are the Different Types of Transaction States in DBMS?

We shall discuss all the different stages as can be seen in the diagram above.

  • Active state: This is the very first state of the transaction. All the read-write operations of the transaction are currently running then the transaction is in the active state. If there is any failure, it goes to the failed state. If all operations are successful then the transaction moves to the partially committed state. All the changes that are carried out in this stage are stored in the buffer memory.

  • Partially Committed state: Once all the instructions of the transaction are successfully executed, the transaction enters the Partially Committed state. If the changes are made permanent from the buffer memory, then the transaction enters the Committed state. Otherwise, if there is any failure, it enters the failed state. The main reason for this state is that every time a database operation is performed, a transaction can involve a large number of changes to the database, and if a power failure or other technical problem occurs when the system goes down the transaction will result in Inconsistent changes to the database.

  • Committed state: Once all the operations are successfully executed and the transaction is out of the partially committed state, all the changes become permanent in the database. That is the Committed state. There’s no going back! The changes cannot be rolled back and the transaction goes to the terminated state.

  • Failed state: In case there is any failure in carrying out the instructions while the transaction is in the active state, or there are any issues while saving the changes permanently into the database (i.e. in the partially committed stage) then the transaction enters the failed state.

  • Aborted state: If any of the checks fail and the transaction reaches a failed state, the database recovery system ensures that the database is in a previously consistent state. Otherwise, the transaction is aborted or rolled back, leaving the database in a consistent state. If a transaction fails in the middle of a transaction, all running transactions are rolled back to a consistent state before executing the transaction.

  • Terminated state: If a transaction is aborted, then there are two ways of recovering the DBMS, one is by restarting the task, and the other is by terminating the task and making itself free for other transactions. The latter is known as the terminated state.

Example

transaction-state-in-dbms2

Let us take a very simple example of Railway ticket booking. Can you think of the things that need to be retrieved from the database when you initiate the booking process?

You will need the train details, the already booked ticket details, the platform details, and many more such things. Now, once these details are retrieved the transaction of booking a ticket enters the active state.

After the user has completed the entire process of booking a ticket from their end, the transaction enters the partially committed state. In case any error occurs during the process, then the transaction will enter the failed state.

Now, say the process was successful and the transaction entered the partially committed state, now if the saving in the database is completed successfully then the transaction enters the committed state. In case there is any error while saving in the database then it enters the failed state.

Anything from the failed state enters the aborted state so that rollbacks can take place and the database consistency is maintained.

Now, let’s talk about the terminated state. If the booking is permanently saved in the database, or it has been aborted due to some unforeseen reasons then the transaction enters the terminated state.

Learn more

Similar topics to learn more about: What is Transaction in DBMS? | Scaler Topics

Conclusion

  • All the read-and-write operations that take place in a database are known as transactions.
  • During the lifecycle of a transaction, it undergoes many phases:
    • Active state
    • Partially committed state
    • Committed state
    • Failed state
    • Aborted state
    • Terminated state