Question

What is difference between Atomicity and consistency ? it looks to me as both are saying same thing in different word.

Atomicity

All tasks of a transaction are performed or none of them are. There are no partial transactions. For example, if a transaction starts updating 100 rows, but the system fails after 20 updates, then the database rolls back the changes to these 20 rows.

Consistency

The transaction takes the database from one consistent state to another consistent state. For example, in a banking transaction that debits a savings account and credits a checking account, a failure must not cause the database to credit only one account, which would lead to inconsistent data.

Was it helpful?

Solution

Atomicity is indeed saying that each transaction is either all or nothing, meaning that either all or none of its actions are executed and that there are no partial operations.

However, consistency talks about ensuring that any transaction will bring the database from one valid state to another. Any data written to the database must be valid according to all defined rules, including but not limited to constraints, cascades, triggers, and any combination thereof (taken from Wikipedia). That basically means that only valid states are written to the database, and that a transaction will either be executed if it doesn't violate the data consistency or rolled back if it does.

Hope it clears things out for you.

OTHER TIPS

simple explain For consistency : if a field-type in database is Integer, it should accept only Integer value's and not some kind of other.If you want to store other types in this field, consistency are violated. At this condition transaction will rollback.

Atomicity :
Bunch of statement just take an example of 100 statements which can be insert statement also , if any of the statement failed while processing should revert back remaining statement , which means database should go back original state.

Blockquote

autocommit = false

try{
   statement one ;
   statement two ;
    `enter code here`
    `enter code here`
    `enter code here`
   statement three;
  }
   catch (){rollback;}
  finally(){commit;} t

Consistency : If your trying to insert date into database which need to be satisfy the constraints, cascades, triggers like while your trying to insert the data into database but the table has primary key constraints so the data your planning to insert should be satisfy with primary key constraint.

Isolation : if two process are running on database assume one is reading and other is writing the data into database . the reading thread should read only committed data , should not be in-memory data

Durability : once transaction data committed into the database should be same stage , it should not affect the from power failure or system crash any other

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top