database atomicity consistency

后端 未结 3 404
执念已碎
执念已碎 2021-01-01 16:23

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

相关标签:
3条回答
  • 2021-01-01 16:46

    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.

    0 讨论(0)
  • 2021-01-01 16:57

    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.

    0 讨论(0)
  • 2021-01-01 17:05

    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

    0 讨论(0)
提交回复
热议问题