Acid
Acid
Atomicity
Key Point: If a transaction involves multiple operations (e.g., inserting data into multiple tables), and
one of those operations fails, the entire transaction is rolled back. No partial updates are made to the
database.
Example:
o Imagine a bank transfer from one account to another. The transaction involves two
steps:
If the first step succeeds but the second step fails (due to a system crash), the atomicity property
ensures that the transaction is rolled back, and neither account is modified. This prevents the
situation where money is deducted from one account but not credited to the other.
2. Consistency
• Definition: Consistency ensures that a database transitions from one valid state to another
after a transaction is completed. The database must always adhere to its rules, constraints,
and relationships, and must not violate any integrity constraints.
Key Point: A transaction will bring the database from one consistent state to another consistent
state, even if the transaction involves multiple operations. The integrity constraints (such as primary
keys, foreign keys, etc.) are preserved, and the database should always remain in a valid state.
Example:
3. Isolation
• Definition: Isolation ensures that the operations of one transaction are isolated from those
of other concurrent transactions. Even if multiple transactions are executing at the same
time, the intermediate steps of one transaction should not be visible to others until the
transaction is fully completed.
Key Point: Isolation prevents "dirty reads," "non-repeatable reads," and "phantom reads." In other
words, a transaction should not see the intermediate, uncommitted changes made by other
transactions that are running concurrently.
Example:
o Consider two users transferring money at the same time from the same account.
Without proper isolation, one transaction might see an intermediate balance before
it has been updated by the other transaction. This could lead to errors such as
overdrawing an account.
Isolation Levels:
o SQL databases support different isolation levels (e.g., Read Uncommitted, Read
Committed, Repeatable Read, Serializable) that define the degree to which
transactions are isolated from each other.
4. Durability
• Definition: Durability ensures that once a transaction has been committed (i.e., successfully
completed), its changes to the database are permanent, even in the case of a system crash,
power failure, or other unexpected events.
Key Point: After a transaction is committed, the database will persist the changes, and they cannot
be undone. The data remains stable and consistent even if the system encounters a failure.
Example:
• Reliability: ACID properties ensure that transactions are reliable and that the database
system will work correctly even in the event of errors or system failures.
• Data Integrity: They maintain the integrity and correctness of the database, ensuring that
the data remains consistent and accurate.
• Concurrency Control: ACID properties, especially isolation, are essential for handling
multiple concurrent users and transactions, making sure they don't interfere with each other.
• Durability: Guarantees that critical business data is not lost, even in the case of unforeseen
events like system crashes.
In conclusion, the ACID properties are fundamental for the proper functioning of a relational
database system, ensuring that the data remains accurate, reliable, and consistent even in complex
scenarios involving multiple concurrent transactions.