Greetings!We have recently published 100+ articles on android tutorials with kotlin and java. If you need, you may visit Android Tutorial for beginners page. You can also check Kotlin Tutorial for beginners. Also, if you are interested in content writing, you can mail us at firstname.lastname@example.org.
In this post, we will learn about different transaction states in dbms with example. We will go through different transaction states – BEGIN, ACTIVE, COMMIT, ROLLBACK etc. in dbms.
A transaction is considered as an atomic operation, but in reality it goes through a number of states during its lifetime.
The transactions boundaries are specified by BEGIN-TRANSACTION and END-TRANSACTION statements. For recovery purpose (in case of data lost), the system needs to keep track of all these states.
As above image clearly depicts, transaction states are –
- BEGIN : The database is in a consistent state before a transaction begins. The transaction on the database begins by the execution of the first statement of the transaction i.e. it becomes active.
- ACTIVE : In the active state, the transaction is modifying the database state. That means, a transaction is performing write operations on the database items, At the end of the active (modify) state, the transaction enters into one of the three states: start to commit, abort or error.
- COMMIT : In the start-to-commit state, the transaction instructs the DBMS to reflect the Change (made by the transaction) into the database . Once all these changes are done in the database, the transaction is said to be in the commit state.
- ROLLBACK : There is a possibility that all the changes made by the transaction are not transmitted to the database due to the hardware or system failures or any errors like dividing by zero. In this case, the transaction enters into the abort or error state and is roll back and ultimately ends the transaction. An aborted transaction that made no changes to the database is terminated (ended) without the need for a rollback.
- END : The transaction can be end in three different ways:
1. Successful termination : A transaction ends after a commit operation.
2. Suicidal termination : A transaction detects an error during its processing and thus aborts and performs a rollback operation.
3. Murderous termination : The operating system or DBMS can force the transaction to be aborted for any reason.