数据库原子性一致性 [英] database atomicity consistency

查看:296
本文介绍了数据库原子性一致性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原子性和一致性有什么区别?



原子性



事务的所有任务或者它们都不是。没有部分事务。例如,如果事务开始更新100行,但系统在20次更新后失败,则数据库会将更改回滚到这20行。



一致性



事务使数据库从一个一致状态到另一个一致状态。例如,在借记储蓄帐户并记入支票帐户的银行交易中,失败不得使数据库仅记入一个帐户,这将导致不一致的数据。

$

$

$

$

$ < b
$ b

然而,一致性涉及确保任何事务将使数据库从一个有效状态到另一个。写入数据库的任何数据必须根据所有定义的规则有效,包括但不限于约束,级联,触发器及其任何组合。
(摘自维基百科)
这基本上意味着只有有效的状态被写入数据库,并且如果事务没有违反数据一致性或者回滚,则执行事务。



希望它为你清理。


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.

解决方案

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.

这篇关于数据库原子性一致性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆