There are a different states of a transaction during its term of execution. A transaction can be in any one of the following states when it is executing:
- Active State: Once a transaction has started executing the first operation, it is said to be in the active state. It stays in the active state till it has executed all the operations of the transaction.
- Partially Committed State: A transaction is said to reach the partially committed state when almost all the operations in the transaction are completed successfully and it has reached till the execution of the last statement or operation of the transaction.
- Failed State: If a problem is encountered during the execution of any operation of the transaction, and the execution can no longer be carried out, then the transaction is said to be in the Failed State. Such a problem may arise due to hardware or logical error. Such a transaction needs to be rolled back or aborted.
- Roll Back or Aborted State: When a transaction has been roll backed and the data in the database comes back in its last saved consistent state, then the transaction is said to be in Roll Back or Aborted State.
- Committed State: Once the transaction has finished executing all of its operations successfully and all the final changes made to the data have been successfully submitted to the database, then we say that it is in the Committed state.
Changes in States of a Transaction
To summarize the States of a Transaction, we can show it in the form of a diagram.
A transaction when started falls in the initial state which is the Active State. It is this state in which a transaction issues various READ and WRITE operations to be executed on the data in the database. A transaction is said to be in an active state until it finishes all of its execution.
In case, a transaction encounters any problem (logical error or hardware issue) then the transaction lands into the state of a failed state transaction. Such a transaction will have to be rolled back so that the database does not lose its consistency. Hence, the transaction once rolled back goes into the rollback or aborted state.
In the roll back or aborted state, the transaction brings the database back into the previous consistent state and the transaction is ended / killed here.
But in case, a transaction does not encounter any problem and it has reached the execution of its last operation in the transaction, then such a transaction is called a partially committed transaction.
And once the transaction has finished executing the last operation of the transaction successfully, this indicates that the transaction has reached the committed state. In the committed state, all the changes made to the database by the transaction are recorded permanently and are reflected in the database.