top of page

Transactions and ACID Properties

Transactions are crucial for ensuring data consistency and integrity, especially when dealing with multiple operations that should either succeed together or fail together.


ree


Importance of ACID Properties:

  • ACID properties are critical for maintaining the integrity and reliability of a database.

  • They provide a framework for designing transactions that can withstand various types of failures, ensuring data consistency and accuracy.


Implementation in SQL:


Two SQL statements implements the ACID properties, they are

  • Commit

  • Rollback


COMMIT used to make the changes of a transaction permanent

ROLLBACK used to undo the changes.


The Below example demonstrates how the concept of 'ACID' ensures that banking transactions, just like interactions at an ATM, are treated as indivisible units, guaranteeing consistency in the event of successes or failures.


-- Begin the atomic transaction

BEGIN TRANSACTION;

-- Step 1: Deduct amount from the account

UPDATE Account SET Balance = Balance - WithdrawalAmount WHERE AccountNumber = '123456';

-- Step 2: Dispense cash

IF DispenseCash(WithdrawalAmount) = SUCCESS THEN

-- Both steps were successful, commit the transaction

COMMIT;

ELSE

-- Dispensing cash failed, rollback the transaction

ROLLBACK;

END IF;


Summary:


Atomicity: 

The BEGIN TRANSACTION and COMMIT statements ensure that both updates (deducting from the sender's account and adding to the recipient's account) occur as a single, atomic unit. If any of these updates fail, the ROLLBACK statement will be executed, ensuring that either both updates are applied or neither.


Consistency: 

The updates to the sender's and recipient's accounts are designed to maintain consistency. The system moves from one valid state (with balances reflecting the transaction) to another. If any update fails, the entire transaction is rolled back, preventing an inconsistent state.


Isolation: 

The database management system ensures isolation by handling concurrent transactions appropriately. If another transaction is being processed simultaneously, changes made by one transaction won't be visible to the other until the transaction is committed.


Durability: 

Once the COMMIT statement is executed, the changes made by the transaction are permanent and will survive system failures. Even if the system crashes after the COMMIT, the database will recover to a consistent state upon restart.



 
 
 

Recent Posts

See All

Comments


MiIT Logo

Company

Contact Us

905-487-4880 

5160 Explorer Dr #34, Mississauga,ON L4W 4T7

646-713-5711

4466 Buttonwood Ln Lilburn, GA 30047

262 Chapman Rd, STE 240 Newark DE 19702

Stay up to date on the latest from MiIT

  • Instagram
  • Facebook
  • http://linkedin.com/company/miittechnologies/about/
  • Whatsapp

© All Content MiIT Technologies Inc.2019 - 2025. All rights reserved.

bottom of page