0
0
DBMS Theoryknowledge~6 mins

ACID properties in DBMS Theory - Full Explanation

Choose your learning style9 modes available
Introduction
Imagine you are saving important information in a database, but sometimes things can go wrong like power failures or errors. How can we be sure that the data stays correct and safe no matter what happens? The ACID properties help solve this problem by making sure database transactions are reliable and consistent.
Explanation
Atomicity
Atomicity means that a database transaction is all or nothing. If any part of the transaction fails, the whole transaction is canceled and the database stays unchanged. This prevents partial updates that could cause errors.
A transaction either completes fully or does not happen at all.
Consistency
Consistency ensures that a transaction brings the database from one valid state to another valid state. It means all rules, like data types and constraints, are followed before and after the transaction.
Transactions must keep the database rules and data valid.
Isolation
Isolation means that multiple transactions happening at the same time do not interfere with each other. Each transaction works as if it is the only one running, so data stays correct even with many users.
Transactions run independently without affecting each other.
Durability
Durability guarantees that once a transaction is finished and confirmed, its changes are saved permanently. Even if the system crashes right after, the data will not be lost.
Completed transactions are saved permanently and safely.
Real World Analogy

Think of sending a package through a delivery service. Atomicity is like the package arriving whole or not at all. Consistency is making sure the package meets all shipping rules. Isolation is when many packages are handled separately without mixing up. Durability is the package staying safe even if the delivery truck breaks down.

Atomicity → The package either arrives complete or not at all
Consistency → The package follows all shipping rules and regulations
Isolation → Each package is handled separately without mixing contents
Durability → The package remains safe even if the delivery truck has problems
Diagram
Diagram
┌─────────────┐
│ Transaction │
├─────────────┤
│ Atomicity   │
│ Consistency │
│ Isolation   │
│ Durability  │
└─────────────┘
This diagram shows the four ACID properties as key parts of a database transaction.
Key Facts
AtomicityEnsures a transaction is fully completed or fully rolled back.
ConsistencyMaintains database rules before and after a transaction.
IsolationPrevents concurrent transactions from interfering with each other.
DurabilityGuarantees that committed transactions are saved permanently.
Code Example
DBMS Theory
import sqlite3

conn = sqlite3.connect(':memory:')
cur = conn.cursor()
cur.execute('CREATE TABLE accounts (id INTEGER PRIMARY KEY, balance INTEGER)')
cur.execute('INSERT INTO accounts (balance) VALUES (100)')
cur.execute('INSERT INTO accounts (balance) VALUES (200)')

try:
    conn.execute('BEGIN')
    cur.execute('UPDATE accounts SET balance = balance - 50 WHERE id = 1')
    cur.execute('UPDATE accounts SET balance = balance + 50 WHERE id = 2')
    # Simulate error
    # raise Exception('Error during transaction')
    conn.commit()
except Exception:
    conn.rollback()

cur.execute('SELECT * FROM accounts')
for row in cur.fetchall():
    print(row)
OutputSuccess
Common Confusions
Believing that isolation means transactions run one after another.
Believing that isolation means transactions run one after another. Isolation means transactions appear to run alone, but they can run at the same time without affecting each other.
Thinking durability means data is saved instantly without delay.
Thinking durability means data is saved instantly without delay. Durability means data is saved permanently after commit, but there may be a short delay during the saving process.
Summary
ACID properties ensure database transactions are reliable and keep data correct.
Atomicity, Consistency, Isolation, and Durability each protect data in different ways.
Together, they help databases handle errors, multiple users, and crashes safely.