Operations and states of Transaction in DBMS

Operations of Transaction:

The main operations of the transaction:

Read(X): Read operation is used to read the value of X from the database and store it in a buffer
in the main memory.
Write(X): Write operation is used to write or update the value back to the database from the buffer.

Example:- Debit transaction from an account :

  1. 1. R(X);
  2. 2. X = X - 500;
  3. 3. W(X);

Let's assume the value of X before starting the transaction is 4000.

  • The first operation reads X's value from the database and stores it in a buffer.
  • The second operation will decrease the value of X by 500. So the buffer will contain 3500.
  • The third operation will write the buffer's value to the database. So X's final value will be 3500.

It may be possible that due to the failure of hardware, software or power, etc. the transaction may fail before finished all the operations in the set.

example: In the above mention transaction, if the debit transaction fails after executing operation 2 then X's value will remain at 4000 in the database which is not acceptable by the bank.

To solve this problem, use the following operations:-

Savepoint:- temporary saving points in the buffer during an inconsistent transaction.
Rollback:  used to undo the work done( save point ). 

Commit: used to save the work done permanently.


States of Transactions

The various states of a Database Transaction are listed below

Active state

  • The active state is the first state of every transaction. 
  • In this state, the transaction is being executed.
  • Example:- Insertion or deletion or updating a record is done here. But all the records are still not saved to the database.

Partially committed

  • In the partially committed state, a transaction executes its final operation, but the data is still not saved to the database.
  • example:- In the total mark calculation, a final display of the total marks step is executed in this state.


In the committed state:- all operations execute successfully and all the effects are permanently saved on the database system.

Failed state

  • If the database recovery system fails, then the transaction is said to be in the failed state.
  • Example:- In total mark calculation, if the database is not able to execute a query to fetch the marks from the database, then the transaction will fail to execute.

Aborted (Terminated)

  • If any of the checks fail and the transaction moves to a failed state then the database recovery system sends the database in its previous consistent state. 
  • If not, then it will abort or roll back the transaction to bring the database into a consistent state.
  • If the transaction fails in the middle of the transaction then before executing the transaction, all the executed transactions are rolled back to their consistent state.
  • After aborting the transaction, the database recovery module will select one of the two operations:
  1. Re-start the transaction
  2. Kill the transaction

Process of transactions:- 

  1. Once a transaction states execution, it becomes active. It can issue READ or WRITE operations.
  2. Once the READ and WRITE operations are complete, the transactions become partially committed state.
  3. Next, some recovery protocols need to ensure that a system failure will not result in an inability to record changes in the transaction permanently. If this check is a success, the transaction commits and enters into the committed state.
  4. If the check is a fail, the transaction goes to the Failed state.
  5. If the transaction is aborted while it's in the active state, it goes to the failed state. The transaction should be rolled back to undo the effect of its write operations on the database.
  6. The terminated state refers to the transaction leaving the system.

check more on the home page & here we have done with transaction management in DBMS

Post a Comment