Transaction States

During the execution, a transaction must be in one of the following states:

Consider a below transaction that transfers 1000 from A to B. Initially, Let A=2000 and B=2000

  1. Active state
    • Initial State
    • When a transaction starts executing, it will be in active state
    • Example:
      • When T1 starts and execute Begin transaction, it is in active state.
      • T1 is in active state from Begin Transaction to Commit
      • In this State, A=2000 and B=2000
  2. Partially Committed State
    • Transaction is in this state after the execution of the final statement.
    • When Transaction executes the COMMIT statement, it will be in Partially Committed State.
    • Example:
      • If T1 reaches the instruction COMMIT, the transaction goes into PARTIALLY COMMITTED state.
      • In this state, A=1000 and B=3000
  3. Committed
    • Transaction is in committed state after successful completion.
    • It is the last state if transaction executes without fail.
    • In this state, all the transactions are permanently saved to the database.
    • Example:
      • If T1 executes COMMIT successfully, the transaction goes into COMMITTED state.
      • In this state, A=100 and B=3000 [New Committed State]
  4. Failed
    • Transaction is in failed state if there is any failure and can not continue the normal execution.
    • Example:
      • If T1 fails in Active State, it goes into Failed State
        • transaction failed before WRITE(A), then A=2000 and B=2000.
        • transaction failed after WRITE(A), then A=1000 and B=2000.
        • transaction failed before COMMIT and after WRITE(B), then A=1000 and B=3000.
      • If the transaction goes into FAILED state from PARTIALLY COMMITTED state, then A = 1000 and B = 3000.
  5. Aborted
    • Transaction is in aborted state after rollback and database restore to its state prior to the start of the transaction.
    • Transaction can be either restarted or killed after it has been aborted.
    • Example:
      • In ABORTED state, A = 2000 and B = 2000. [A and B are rolled back to Old consistent state]

Leave a Reply

Notify of