Introduction to DBMS transaction and its ACID properties

Posted By :Dimpal Bhatia |29th June 2019

Transaction:- A transaction is a single unit of work which modifies and accesses the contents of a database. It can be defined as a group of tasks. A single task can not be divided further because it is the minimum processing unit. Transactions perform read and write operations on data.


States of Transactions:-
A transaction in a database has following states 

1) Active:-  Initial state of every transaction is Active. In this state, the transaction is being executed.

2) Partially Committed:-  A transaction is in partially committed state when transaction executes its final operation.

3) Failed:-  If any of the checks made by the database recovery system fails then transaction is said to be in a failed state. A failed transaction can not perform further operations.

4) Aborted:- Transaction has reached a failed state if any of the checks fail, then the recovery manager bring the database back to its original state where it was prior to the execution of the transaction by rolls back all its write operations on the database.   This state of transactions is called aborted.

The database recovery module selects one of the two operations after transaction aborts:-

a ) Re-start the transaction
b ) Kill the transaction

5) Committed:-  When transaction executes all its operations successfully, then it is said to be committed. All the effects of transaction are now permanently established on the database system.

                                

ACID Properties in DBMS

Atomicity:- It means either the entire transaction takes place at once or doesn't happen at all. Each transaction is called as one unit and either not executed at all or runs to completion. There is no midway.

Consider the transaction T consist of T1 and T2 Transfer of 100 from account X to account Y
If the transaction fails after completion of T2 but before completion of T1.( say, after write(y) but before write(x)), then the amount has been deducted from y but not added to X. It results in an inconsistent state of the database. Therefore, the transaction must be executed completely in order to ensure the correctness of database state.

 

Consistency:- This means that the database should be inconsistent before and after the transaction so,  Integrity constraints must be maintained to fulfill the requirement. It means correctness of a database before and after transaction. 
The total amount must be maintained before and after the transaction.
Total before T1 occurs = 600 + 200 = 800.
Total after T1 occurs = 500 + 300 = 800.
Therefore, the database is consistent. Inconsistency occurs in case T2 completes but T1 fails. As a result, T is incomplete.


Isolation:- This property ensures that multiple transactions can perform simultaneously without effecting the  consistency of database state. Transactions can occurs independently without interference. Changes occurring in one transaction will not be visible to any other transaction until that particular change  has been committed or is written to memory in that transaction. It ensures that the execution of transactions concurrently will result in a state that is similar to a state achieved these were executed serially in some order.
Let A= 500, B = 500.
Consider two transactions T and T”.

Let T has been executed till reading (B) and then T'' starts. As a result, interleaving of operations can take place due to which T'' reads the incorrect value of B and correct value of A and sum computed by
T'': (A+B = 50, 000+500=50, 500)
is thus not consistent with the sum at end of transaction: 
T: (A+B = 50, 000 + 450 = 50, 450).
Due to a loss of 50 units, this results in database inconsistency. 

 

Durability:-This property performs updates and modifications to the database  are stored in and written to disk once the transaction has been executed completely. The updates are stored in non-volatile memory and become permanent. The effects of transaction never lost.

 


About Author

Dimpal Bhatia

She is a bright java developer. She has a good knowledge of JavaScript, jQuery, JSP, and ElasticSearch. Her hobbies are playing badminton and reading books

Request For Proposal

[contact-form-7 404 "Not Found"]

Ready to innovate ? Let's get in touch

Chat With Us