Introduction to ACID Properties ACID properties ensure reliable processing of transactions in a database system. - A: Atomicity (All or nothing rule) - C: Consistency (Data integrity) - I: Isolation (Concurrent transactions) - D: Durability (Permanent effect after transaction commit)
Atomicity Atomicity ensures that a transaction is all-or-nothing. Either every operation within the transaction is executed, or none are. Example: Bank Transfer - Transfer ₹1000 from Account A to Account B. - Subtract ₹1000 from Account A. - Add ₹1000 to Account B. If one of these operations fails, the entire transaction is rolled back, leaving both accounts unchanged.
Consistency Consistency ensures that a transaction brings the database from one valid state to another, maintaining data integrity. Example: Bank Balance - Before a transfer, total funds across all accounts should be the same before and after the transaction. - Constraints like "Balance cannot be negative" must always be true.
Isolation Isolation ensures that multiple concurrent transactions occur independently without interference. Example: Two transfers - If two people are transferring money at the same time, their transactions should not affect each other. Each transaction is isolated from others.
Durability Durability ensures that once a transaction is committed, its result will persist even in the event of a system failure. Example: Power Outage - After successfully transferring ₹1000 from Account A to B, even if the system crashes or loses power, the transfer should still be reflected in the database when it restarts.
Real-world Example: Bank Transaction Consider transferring ₹1000 from Account A to Account B: 1. **Atomicity**: Either ₹1000 is debited from A and credited to B, or neither happens. 2. **Consistency**: Total balance across both accounts should remain the same before and after. 3. **Isolation**: Other transactions should not interfere, and vice versa. 4. **Durability**: Once the transfer is complete, it will not be lost, even if the system crashes.
Summary of ACID Properties - **Atomicity**: Complete all steps or none. - **Consistency**: Maintain data integrity. - **Isolation**: Transactions run independently. - **Durability**: Changes persist permanently. These properties are essential for ensuring reliable and predictable database transactions.