DEV Community

Cover image for Acid Property with SQL Transactions
Kausi Tarun
Kausi Tarun

Posted on

Acid Property with SQL Transactions

πŸ”· Introduction to ACID Properties in SQL Transactions

In SQL databases, a transaction is a sequence of one or more SQL operations (like INSERT, UPDATE, or DELETE) executed as a single unit of work.
To ensure the reliability and consistency of data, transactions must follow the ACID properties.

1.Create a table Accounts(acc_no INT PRIMARY KEY, name VARCHAR(50), balance INT). Insert 3 sample rows.

2.Atomicity: Start a transaction that transfers money. Rollback midway β†’ ensure no partial update remains.

3.Consistency: Try inserting a record with negative balance β†’ should be rejected.

4.Isolation: Run two sessions at once – one updating, the other reading β†’ observe isolation.

Durability: Commit a transaction β†’ restart DB β†’ ensure data persists.

Top comments (0)