数据完整性和数据一致性之间有什么区别吗?

发布于 2024-10-15 11:15:45 字数 709 浏览 9 评论 0原文

我对数据一致性数据完整性有点困惑。来自Oracle 数据库概念

data integrity
--------------
Business rules that dictate the standards for acceptable data. These rules
are applied to a database by using integrity constraints and triggers to
prevent invalid data entry.

来自 Wikipedia

Consistency
-----------
Consistency states that only valid data will be written to the database.

那么数据一致性数据完整性

提前致谢。

I'm a little confused about data consistency and data integrity. From Oracle Database Concepts:

data integrity
--------------
Business rules that dictate the standards for acceptable data. These rules
are applied to a database by using integrity constraints and triggers to
prevent invalid data entry.

From Wikipedia

Consistency
-----------
Consistency states that only valid data will be written to the database.

So what's the difference between data consistency and data integrity?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

浅笑依然 2024-10-22 11:15:45

它们不仅不同,而且是正交的。

不一致
如果数据库将员工 Joe Shmoe 的部门报告为销售部门,但未将 Joe Shmoe 列为销售部门的员工,则会出现不一致。
这是数据库的逻辑属性,与实际情况无关。数据

诚信
如果数据库报告 jOe SaleS 是 Shmoe 部门的成员,则缺乏诚信。
jOe SaleS 不是有效的员工姓名,Shmoe 也不是有效的部门。
这不是逻辑上无效,但相对于管理数据内容的规则来说它是无效的

They are not only different, they are orthogonal.

Inconsistency:
A DB that reported employee Joe Shmoe's department as Sales but that didn't list Joe Shmoe among the employees in the Sales department would be inconsistent.
It's a logical property of the DB, independent of the actual data.

Integrity:
A DB that reported jOe SaleS to be a member of the Shmoe department would lack integrity.
jOe SaleS isn't a valid employee name and Shmoe isn't a valid department.
That's not logically invalid, but it is invalid relative to the rules that govern data content.

自此以后,行同陌路 2024-10-22 11:15:45

非常粗略地说,我的 2c:

完整性 = 强类型,没有由数据模型和数据确定的非法值。约束、外键、唯一约束等等。

一致性=只能读取给定时间点提交的数据,而不是中间步骤。

Very roughly, my 2c:

Integrity = strong types, no illegal values as determined by the data model & constraints, foriegn keys, unique constraints and stuff like that.

Consistency = being able to read only committed data a given point in time, not the intermediate steps.

上课铃就是安魂曲 2024-10-22 11:15:45

数据可能完全一致,也可能完全错误。数据完整性更多的是关于数据的质量,并且远远超出了数据库管理系统的范围。 DBMS 提供数据一致性工具,有助于保证数据完整性;它们只是更大问题的一部分。完整性约束和触发器有助于确保 DBMS 不会降低(或者,如果您是悲观主义者,则进一步降低)到达数据的完整性。

解析 Oracle 术语的方法是,完整性约束和触发器是实现定义数据完整性的业务规则子集的一种方法。

Data can be entirely consistent and entirely wrong. Data integrity is more about the quality of data and goes well beyond data base management systems. DBMSs provide data consistency tools that can help with data integrity; they are one piece of the larger problem. Integrity constraints and triggers help ensure that a DBMS does not degrade (or, if you're a pessimist, further degrade) the integrity of the data that arrives.

The way to parse the Oracle verbiage is that integrity constraints and triggers are a way to implement a subset of the business rules that define data integrity.

遇到 2024-10-22 11:15:45

来自此处

数据一致性

隔离执行事务可以保持数据的一致性。数据库中存储的数据值必须满足一定的一致性约束。例如,账户余额不应低于 100 美元。 DDL 命令提供了指定此类约束的工具。每次更新数据库时,数据库系统都会检查这些约束。一般来说,它可以是与数据库相关的任意谓词。为了检查数据库的一致性,大多数程序员依赖于约束,而这些约束通常测试成本很高。

数据完整性

数据完整性是指“整个数据位于一处”。数据以表格的形式存在,每个表格都有一些属性。在这些情况下,我们希望确保出现在给定属性集的一个关系中的值也应该出现在另一关系中的特定属性集(引用完整性)。数据库修改可能会导致完整性遭到破坏。当完整性约束被违反时,正常过程会拒绝实际导致违规的操作。

在此处输入图像描述

您可以阅读 ACID 第一章

From here

Data consistency

Execution of transaction in isolation preserves the consistency of the data. The data value stored in the database must satisfy certain consistency constraints. For example the balance on an account should not fall below $100. The DDL commands provide the facilities to specify such constraints. The database systems check these constraints every- time the database is updated. In general it can be an arbitrary predicate pertaining to the database. To check the consistency of database most of programmer depends on the constraints and these are usually costly to test.

Data integrity

The integrity of data refers to as "whole data at one place". The data is in the form of tables and each table has some attributes. These are the cases where we wish to ensure that a value that appears in one relation for given set of attributes should also appear for a certain set of attributes in another relation (referential integrity). Database modification can cause violation of integrity. When the integrity constraint is violated, the normal procedure rejects the action that has actually caused the violation.

enter image description here

You can read first chapter for ACID.

旧街凉风 2024-10-22 11:15:45
  1. 一致性:同一列中没有日期、数字和字母,而只有其中之一。
    这是通过定义列类型来实现的,例如。列 ID 号 (5) 意味着其中不会有日期或字母,并且数字大于 99999
  2. 完整性:如果您有员工表和部门表以及部门 ID 列(其中部门 ID 的含义是员工正在工作)不会有任何员工在部门表中不存在的部门工作。
    这是由引用完整性约束造成的。
  1. Consistency: You don’t have dates, number and letters in same column but only one of them.
    This is forsed by defining column type, eg. column id number (5) means there won’t be dates nor letters in it and numbers greater then 99999
  2. Integrity: If you have emplooyes table and departments table and department_id column in both of them (with meaning of department_id in witch employee is working) there won’t be any employee working in department that doesen’t exists in departments table.
    This is forsed by referencal integrity constraint.
鸠书 2024-10-22 11:15:45

一致性:
一致性是指数据库中数据的逻辑正确性。在任何操作或事务之后,数据必须保持逻辑正确。

示例:如果您向产品表中添加 5 个苹果,然后出售 3 个苹果,则表中应该还剩下 2 个苹果。如果产品表显示不同的数字(例如1或4),则数据不一致。

诚信:
假设您有一个 Gender 表和一个 Person 表,其中 Person 表有一个引用 Gender 的性别 ID 列code> table (这个引用并不意味着外键约束,暂时认为数据库中没有外键约束的概念)。如果您从 Gender 表中删除一条记录,则 Person 表中的记录的性别 ID 可能不再存在于 Gender 中表中,这在逻辑上并没有错误 - 这意味着该人没有性别信息。

但问题是:如果从Gender表中删除一条记录,Person表中的相关记录会发生什么或者如何确保有相同的值性别 ID 位于 Gender 表中。

现在我们来介绍一下外键约束的概念。此约束确保 Person 表中具有性别 Id 的值必须出现在 Gender 表中。再次引入另一个 Constantin Cascading 引用完整性约束,这将确保当您从 Gender 表中删除一条记录时,Person 表的记录会发生什么情况。

因此,完整性根据定义的规则或约束确保数据库内数据的正确性、有效性和准确性。

Consistency:
Consistency refers to the logical correctness of the data in a database. After any operation or transaction, the data must remain logically correct.

Example: If you add 5 apples to your product table and then sell 3 apples, there should be 2 apples left in the table. If the product table shows a different number (e.g., 1 or 4), the data is inconsistent.

Integrity:
Suppose you have a Gender table and a Person table, where the Person table has a gender ID column that references the Gender table (This reference doesn’t mean the foreign key constraint, for now just think there is no concept of foreign key constraint in Database). If you delete a record from the Gender table, there could be records in the Person table with a gender ID that no longer exists in the Gender table, this is not logically wrong - it means the person has no gender information.

But the question is: If you delete a record from the Gender table, what happens to the related records in the Person table or how do you ensure that there is a same value with gender Id in Gender table.

Now let's introduce the concept of foreign key constraints. This constraint ensures that the value with gender Id in the Person table must be present in the Gender table. Again, introduce another Constantin Cascading referential integrity constraints this will ensure that what will happen to the record of Person table when you delete a record from Gender table.

Thus, integrity ensures the correctness, validity, and accuracy of data within a database according to defined rules or constraints.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文