A transaction consists of the number of operations that are performed on the database. These operations are executed in the form of a single unit that may or may not change the data of the database, so as to ensure consistency and maintain integrity constraints. Once the transaction is submitted it should perform all the operations it consists and finally, when it is completed database should notify the success or failure and the changes it performs.
When multiple users have submitted the transaction at the same time, it will result to an inconsistent state. This state arises because of the transaction’s overlap. Therefore in order to maintain integrity in case of concurrent access and system failure, the transaction should have atomicity, consistency, isolation and durability properties. These are known as ACID properties. The acronym of ACID is atomicity, consistency, isolation and durability. So, the properties of transactions are divided into four parts mentioned below:
Let us discuss all these properties :
This first ACID property is defined by the phrase “all or nothing”.The atomic property is said to be achieved if the transaction runs to completion or it has made no effects at all if it is incomplete. Simply, the effects of transactions on a database should be either executing all its actions in one step or not executing any actions at all.
Features of Atomicity
- All the transactions should be completed successfully or none are.
- In the phase of CPU failure, database software failure and Application software failure atomicity is maintained.
- During deadlocks, atomicity is maintained.
- It is the responsibility of the database to maintain atomicity.
Let’s consider A and B are two accounts having Rs.5000 and Rs.8000 respectively. Also, consider T1 and T2 are transactions. Now suppose after the execution of the transaction (T1) failure occur that prevent transaction T2 from completely executed.
As the failure occur after the completion of operation write(A) but before the execution of write( B). Consequently, the value in accounts A and B now are Rs.4250 and 8000. respectively. It is clear that the Rs.750 amount is lost due to the failure. This results in an inconsistent state of the database because the transaction is partially completed. In order to maintain consistency and to ensure atomicity either all the transaction operations should be completed or none of them affects the data during failure situations.
The consistent state is maintained when DBMS restores the original values of A and B. So database should track the old values of any data on which write operations are performed. In case of transaction failure, it should restore the old values to appear that nothing has happened.
The ‘No violation of integrity constraints’ phrase is used to define the consistency property. This property is said to be fulfil if the DBMS before the start of the transaction and after the completion of the transaction is in a consistent state. Maintaining consistency is the responsibility of the programmer who writes the code.
The database is said to be in a consistent state when before and after the completion of transactions sum in both accounts A and B are the same. Keep an eye on the data of below table :
|Before the execution of transaction value in Accounts
|Before the execution of transactions, Total sum is
|After the completion of transactions value in Accounts
|After the completion of transactions, Total sum is
From the above table, it is crystal clear that before the start of transactions on accounts A and B the sum of the amount is Rs.13000. And after the completion of the transactions, the sum of the total amount is also Rs.13000. So here database is in a consistent state in both the situations.
When transactions executes in concurrent phase then there is a need to maintain isolation. The concurrent transaction here refers to the access of the database at the same time by multiple users.
The isolation property will achieve if several transactions results the same as if they will executes concurrently or serially. The data use by one transaction should not use by the other transaction until the first completes its execution successfully.
The problem to satisfy atomicity and consistency come into existence when two transactions executes concurrently. The main reason for these problems is because of the overlapping of concurrently running transactions. Now suppose transactions T1 and T2 are executes currently. Also, consider the transaction T1 transfer the amount of Rs.750 from A to B. The transaction T2 transfers 20% of the amount from Account A to B. The initial values in A and B accounts are Rs.5000 and Rs. 8000.
Now the schedule for transactions T1 and T2 running concurrently as mentioned in schedule 1. It results in a consistent state of DBMS before and after the execution of transactions.
From the above two tables, it is crystal clear that schedule 1 results in a consistent state of the database whereas Schedule leads to an inconsistent state.
Sechdule1 Table (Consistent State)
Store to A
Store to A
Store to B
Store to B
In schedule 1 ,when transaction T1 complete its operations on one account only then the T2 transaction used the data of that account. In the table, it is clear that initially read operation is perform on account A . This shows the amount in A is Rs.5000. Now Rs.750 deducted from account A. The transaction then updated the value of account A to Rs.4250 by using the write operation.
Now T2 starts with the read(A) operation which indicates that A has Rs.4250. Now a 20% amount of account A is calculated and Rs.850 amount stored in temp variable. Now Rs. 850 amount deducted from account A and then with the help of Write (A) amount update to Rs.3400 in A account.
After that Read(B) operation perform by the T1 transaction. Then Rs.750 amount add to account B and the value is then update as Rs.8750.
Hereafter ,T2 reads the value of account B which is Rs.8750. Then temp variable value(Rs.850) store to B . The amount is updated as Rs.9600 in account B.