database atomicity consistency database atomicity consistency database database

database atomicity consistency


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.


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.

autocommit = falsetry{   statement one ;   statement two ;   statement three;}catch (){rollback;}finally(){commit;}

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