A transaction is a single logical unit of work. It accesses and generally modifies the contents of a database. Transactions access data using READ and WRITE operations.
In order to maintain consistency in a database, before and after the transaction, certain properties need to be followed. These properties are called ACID properties.
ACID is the short form for Atomicity Consistency Isolation Durability. More on this can be found out from the image below:
Atomicity : By this it is meant that either the entire operation transaction takes place or no transaction takes place at all. It basically involves two operations :
- Abort : If for any reason, the transaction is aborted, the changes made to the database is not visible.
- Commit : If the transaction happens successfully, the changes are visible.
Atomicity is often referred to as the "All or Nothing Rule".
Consistency : It means that the integrity constraints of the database must be preserved. It is to make sure that the database is consistent both before and after the transaction. It refers to the correctness of the database.
Isolation : This property ensures that multiple transactions can occur simultaneously without the database state being inconsistent. In other words, it takes care that that the transactions occur independently without interference.
Durability : As the name suggests, this property 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 a system failure occurs. These updates now become permanent and are stored in the non-volatile memory. The effects of the transaction, thus, are never lost.