Transaction in DBMS

Transaction :

  • A transaction can be defined as an action or series of actions that is carried out by a single user or application program to perform operations for accessing the contents of the database. The operations can include retrieval, (Read), insertion (Write), deletion and modification.
  • A transaction is a sequence of READ and WRITE actions that are grouped together to from a database access.
  • Each transaction should access shared data without interfering with the other transactions and whenever a transaction successfully completes its execution; its effect should be permanent.

Transaction States

In a database, the transaction can be in one of the following states:

Transaction State

Active state

  • The active state is the first state of every transaction. In this state, the transaction is being executed.
  • For 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.
  • In the total mark calculation example, a final display of the total marks step is executed in this state.

Committed

A transaction is said to be in a committed state if it executes all its operations successfully. In this state, all the effects are now permanently saved on the database system.

Failed state

  • If any of the checks made by the database recovery system fails, then the transaction is said to be in the failed state.
  • In the example of total mark calculation, if the database is not able to fire a query to fetch the marks, then the transaction will fail to execute.

Aborted

  • If any of the checks fail and the transaction has reached a failed state then the database recovery system will make sure that the database is 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 its 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

Transaction Properties :

A transaction must have the following four properties, called ACID properties to ensure that a database remains stable state after the transaction is executed:

  1. Atomicity
  2. Consistency
  3. Isolation
  4. Durability

1.Atomicity :

  • It means the entire transaction complete successfully ordoesn’t happen at all.
  • Atomicity is also known as the �All or nothing rule’.
  • There is no midway i.e. transactions do not occur partially.

2.Consistency

  • It ensures bringing the database from one consistent state to another consistent state.
  • It ensures the execution of a transaction must leave a database in either its prior stable state or a new stable state that reflects the new modifications (updates) made by the transaction.
  • If the transaction fails, the database must be returned to the state it was in prior to the execution of the failed transaction.
  • If the transaction commits, the database must reflect the new changes.Thus, all resources are always in a consistent state.

3.Isolation:

  • It ensures the transaction is isolated from other transaction.
  • It ensures that the data which is used at the time of execution of a transaction cannot be used by the second transaction until the first one is completed.

4.Durability

  • The database should be durable enough to hold all its latest updates even if the system fails or restarts.
  • If a transaction commits but the system fails before the data could be written on to the disk, then that data will be updated once the system springs back into action.
  • Durability property is the responsibility of the recovery subsystem of the DBMS.

Leave a Reply

Your email address will not be published. Required fields are marked *