数据库原子性一致性

编程入门 行业动态 更新时间:2024-10-28 08:21:03
本文介绍了数据库原子性一致性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

原子性

事务的所有任务或者它们都不是。没有部分事务。例如,如果事务开始更新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.

更多推荐

数据库原子性一致性

本文发布于:2023-11-17 06:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609091.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:原子   数据库   性一致性

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!