Updated March 3, 2023
Introduction to States of Transaction in DBMS
States of the transaction are the situation and condition in which a transaction in DBMS is currently present. There are many states of transaction like active, failed, committed, aborted and partially committed. A particular transaction can only be in one state at a given time. This state of the transaction helps us to know about the present situation in which the transaction is working and also guides us through how the transaction will proceed further in future. The state of the transaction also tells us about the rules and the way in which the transaction will proceed which will ultimately lead to either commitment or abortion of the transaction.
In this article, we will learn about different states of the transaction in DBMS and also see what rules are followed by each of the state and how each state defines the behavior of the transaction at that particular moment.
Different States of the Transaction in DBMS
Let us discuss different states of the transaction in DBMS.
1. States of Transaction
What happens on the DBMS transaction is that number of small read and write operations are performed on the database and together small tasks of read and write tasks performing similar work are collectively called as transaction. A transaction consisting of group of small tasks can either commit or fail. In between the initialization and completion of the transaction, there are different states involved in the process. The different states of the transaction are described below in detail –
2. Active State
Whenever any database operation is performed on the database like updation, deletion, or insertion which involves the change in the database or even the select operation which involves the retrieval of the data from the database the transaction is started and the beginning state of every transaction is the active state in which whatever instructions are involved in the transaction are and if all the operations are executed successfully then the transaction goes into the partially committed state. In case if any problem occurs while executing any of the instruction in the transaction then the transaction goes into the failed state.
3. Partially Completed State
After all the operations are performed in the transaction the transaction comes into a partially committed state where all the changes are made to the main memory or the local buffer which are temporary in nature. If the changes are made properly then the transaction moves to a committed state where the changes are reflected permanently in the database or in case of any failure in performing the temporary changes the transaction goes into the failed state.
The main purpose for having this state is that whenever we perform database operations the transactions may involve huge amount of changes to be made to the database and in case of power failure or any other technical issue if the system fails then the transaction will lead to inconsistent changes made to the database. To avoid this, we firstly make all the changes to the local repository or reader buffer or main memory for temporary basis so that in case of failure the changes can be reverted and transaction can be rollbacked. This will lead to the implementation of consistency property of the ACID properties of transaction which is the expected behavior for any transaction.
4. Failed State
In case if any of the instruction fails to perform correctly or the changes are being saved to the memory properly then the transaction comes into the failed state.
5. Aborted State
In case if any failure occurs while executing instructions or while making the changes to the memory the state of the transaction changes to aborted after failed where all the changes made to the local memory and the buffer reader are reversed that is deleted or rollbacked.
6. Committed State
Whenever all the instructions inside the transaction are executed successfully and the changes are made to the local memory or the reader buffers successfully then the transaction comes into the committed state where all the changes of the transaction are made permanently to the database. Once the transaction is committed the changes cannot be rollbacked and the transaction then goes into the terminated state where the system is ready to restart the transaction or begin a new one.
7. Terminated State
If there is any problem while executing the transaction, instruction of change reflection and the transaction is in the failed state then the transaction the changes are rollbacked and the transaction comes into terminated state after aborted state. Also, in case if all the operations are performed properly and changes are reflected the database appropriately then the transaction comes into the terminated state after committed state. In the terminated state the transaction is finally completed and the system is ready and consistent for the upcoming transaction to be taken and the old transaction to be stopped.
In case if the transaction fails and goes to aborted state then the database recovery system of DBMS has two options. The first one being the uncompleted, inconsistently or partial the system can restart the same transaction from beginning or the system will kill the ongoing transaction and will make itself free for any further tasks or transaction that the user will begin.
Consider a small example where the businessman wants to save the total sale of whole day in the database. In this case, the transaction will involve the retrieval of all the bill records for the day and then the transaction will enter into the active state where the calculation of the total sale amount of the day will be made. After that if calculation is done successfully then the transaction will move to partially committed state else will go to the failed state. In partially committed state the system will save the total calculated amount to the local main memory and if this is done successfully then the transaction will move on to commit state or will go to a failed state. In committed state the total amount will be saved permanently to the database and the transaction will move onto the terminated state. In case of the failed state transaction the changes are rollbacked and transaction goes to the aborted state where system becomes free.
A transaction in DBMS involves multiple states which define the condition and situation of the transaction at a particular moment. A single transaction can be only in a single state at a given time.
This is a guide to States of Transaction in DBMS. Here we discuss the introduction, Different States of the Transaction in DBMS respectively. You may also have a look at the following articles to learn more –