🔐 ACID PROPERTIES IN DBMS
Atomicity • Consistency • Isolation • Durability
📘 What are ACID Properties?
ACID properties are four important characteristics that make database transactions reliable and safe.
A = Atomicity | C = Consistency | I = Isolation | D = Durability
A transaction should either complete correctly or leave the database in a safe state.
ACID properties are four important characteristics that make database transactions reliable and safe.
A = Atomicity | C = Consistency | I = Isolation | D = Durability
A transaction should either complete correctly or leave the database in a safe state.
🔐 Four ACID Properties
| Property | Meaning | Simple Idea |
|---|---|---|
| Atomicity | All or Nothing | Complete transaction or rollback |
| Consistency | Valid State | Rules and constraints remain valid |
| Isolation | Transactions are separated | Concurrent transactions should not interfere incorrectly |
| Durability | Permanent Result | Committed data survives failures |
ACID = Atomicity + Consistency + Isolation + Durability
⚛️ A — Atomicity
Atomicity means a transaction is treated as
one complete unit.
Either all operations are completed, or none of them are applied.
Either all operations are completed, or none of them are applied.
Example: Bank Transfer
Account A → ₹1000
Account B → ₹500
Transfer = ₹200
Account B → ₹500
Transfer = ₹200
1
₹200 is deducted from Account A.
2
₹200 is added to Account B.
Both operations succeed.
A = ₹800
B = ₹700
Transaction COMMIT.
A = ₹800
B = ₹700
Transaction COMMIT.
What if the second operation fails?
The ₹200 deduction from A must also be cancelled.
This is called ROLLBACK.
Therefore:
Either both operations happen, or neither happens.
This is called ROLLBACK.
Therefore:
Either both operations happen, or neither happens.
✅ C — Consistency
Consistency means a transaction must take the
database from one valid state to another valid state.
All database rules, constraints and relationships must remain valid.
All database rules, constraints and relationships must remain valid.
Example
Total Bank Balance Before
= ₹10,000
Total Bank Balance After = ₹10,000
Total Bank Balance After = ₹10,000
If ₹2,000 is transferred from Account A to Account B, the total amount should remain unchanged.
1
A loses ₹2,000.
2
B gains ₹2,000.
3
Total money remains the same.
Database rules remain valid.
Therefore the transaction preserves consistency.
Therefore the transaction preserves consistency.
🔒 I — Isolation
Isolation means that multiple transactions executing
at the same time should not incorrectly interfere with one another.
Example
Suppose two transactions are running simultaneously:
Transaction T1 → Withdraw ₹500
Transaction T2 → Deposit ₹1000
Transaction T2 → Deposit ₹1000
1
T1 and T2 execute concurrently.
2
The intermediate changes of one transaction should not incorrectly
affect the other transaction.
3
The DBMS controls concurrent execution using mechanisms such as
locking or other concurrency-control techniques.
The final result should be equivalent to a correct serial execution.
This is the purpose of Isolation.
This is the purpose of Isolation.
💾 D — Durability
Durability means that once a transaction has been
successfully committed, its changes should remain saved even if
a system failure occurs afterward.
Example
1
A customer deposits ₹5,000.
2
The transaction completes successfully.
3
The DBMS executes COMMIT.
4
Immediately afterward, the computer crashes.
After the database system recovers,
the committed ₹5,000 deposit should still be present.
That is Durability.
That is Durability.
🏦 Complete Bank Transfer Example
T1: Transfer ₹500 from A to B
Initial State
| Account | Balance |
|---|---|
| A | ₹5000 |
| B | ₹3000 |
Transaction
A = A − 500
B = B + 500
B = B + 500
Final State
| Account | Before | After |
|---|---|---|
| A | ₹5000 | ₹4500 |
| B | ₹3000 | ₹3500 |
Atomicity: Both updates happen or neither.
Consistency: Total balance remains ₹8000.
Isolation: Other transactions do not see an incorrect intermediate state.
Durability: After COMMIT, the result remains saved.
Consistency: Total balance remains ₹8000.
Isolation: Other transactions do not see an incorrect intermediate state.
Durability: After COMMIT, the result remains saved.
🧮 ACID Transaction Step-by-Step
1
BEGIN TRANSACTION
The transaction starts.
The transaction starts.
2
READ DATA
The required account information is read.
The required account information is read.
3
PERFORM OPERATIONS
Money is deducted from one account and added to another.
Money is deducted from one account and added to another.
4
CHECK CONSISTENCY
Database constraints and rules must remain valid.
Database constraints and rules must remain valid.
5
COMMIT
If everything succeeds, the transaction is committed.
If everything succeeds, the transaction is committed.
6
FAILURE?
If an operation fails, the transaction can be rolled back.
If an operation fails, the transaction can be rolled back.
SUCCESS → COMMIT
FAILURE → ROLLBACK
FAILURE → ROLLBACK
⚠️ What Happens During Failure?
Suppose ₹1000 is transferred from Account A to Account B.
1
₹1000 is deducted from A.
2
System failure occurs before ₹1000 is added to B.
3
Atomicity requires the incomplete transaction to be undone.
4
The DBMS performs recovery/rollback as appropriate.
The database returns to a correct state.
Incomplete transaction → ROLLBACK
Incomplete transaction → ROLLBACK
📊 ACID Properties Comparison
| Letter | Property | Main Question |
|---|---|---|
| A | Atomicity | Did everything happen or nothing? |
| C | Consistency | Are database rules still valid? |
| I | Isolation | Are concurrent transactions safely separated? |
| D | Durability | Will committed data survive failure? |
A → ALL OR NOTHING
C → VALID STATE
I → SAFE CONCURRENT EXECUTION
D → PERMANENT COMMIT
C → VALID STATE
I → SAFE CONCURRENT EXECUTION
D → PERMANENT COMMIT
❓ Short Questions & Answers
Q1. What does ACID stand for?
ACID stands for Atomicity, Consistency, Isolation and Durability.
These properties help maintain reliable database transactions.
Q2. What is Atomicity?
Atomicity means that a transaction is treated as one unit.
Either all its operations are completed or none are applied.
Q3. What is Consistency?
Consistency ensures that a transaction takes the database from
one valid state to another valid state while maintaining database
constraints and rules.
Q4. What is Isolation?
Isolation ensures that concurrently executing transactions do not
produce incorrect results because of interference between them.
Q5. What is Durability?
Durability means that once a transaction is committed, its changes
remain preserved even after a subsequent system failure.
Q6. What is COMMIT?
COMMIT permanently accepts the successful changes made by a
transaction.
Q7. What is ROLLBACK?
ROLLBACK cancels the changes of an incomplete or unsuccessful
transaction and restores an appropriate previous database state.
No comments:
Post a Comment