In relational databases, transaction is a single logical unit of work. Transactions access or manipulate data using read and write operations. In order to work database operations in consistent way, certain properties are followed, and these are called ACID properties.
A – Atomicity (All operations either fail or succeed in single transaction)
C – Consistency (Refers to correctness of database after a transaction)
I – Isolation (Concurrent transactions execute independently without interfering)
D – Durability (If transaction is committed, data is stored in non-volatile memory)
Consider the following transaction T consisting of T1 and T2: Transfer of 100 from account A to account B.
If the transaction fails after completion of T1 but before completion of T2, then amount has been deducted from A but not added to B. This results in an inconsistent database state. Therefore, the transaction must be executed entirety in order to ensure correctness of database state.
This means that integrity constraints, triggers, rules etc. must be maintained so that the database is consistent before and after the transaction. It refers to correctness of a database.
Isolation ensures that multiple transactions can occur concurrently without leading to inconsistency of database state. Transactions occur independently without interference. Changes occurring in a particular transaction will not be visible to any other transaction until that change in that transaction is written to memory or has been committed. This property ensures that the execution of transactions concurrently will result in a state that is equivalent to a state achieved these were executed serially in some order.
Durability ensures that once the transaction has completed execution, the updates and modifications to the database are stored in and written to disk and they persist even if system failure occurs. These updates now become permanent and are stored in a non-volatile memory. The effects of the transaction, thus, are never lost.