Chapter 2 Relational Database (2)

Section 2 Data Integrity Rules

Data integrity refers to the correctness and validity of data. The integrity rule of the relationship is to ensure that the value of the relationship must meet the constraints. The relationship model has three types of integrity constraints, namely entity integrity, referential integrity, and user-defined integrity. Among them, entity integrity and referential integrity are integrity rules that all relational databases must satisfy, also known as relational integrity constraints. Relationship integrity rules are used to ensure that the values ​​of the primary and foreign keys of the relationship must be correct and valid. User-defined integrity is a specific constraint that needs to be followed in the user application environment, and reflects special business rules in the user application environment.
1. Entity integrity
The value of the primary key must be unique and determined to effectively identify a tuple. Entity integrity means that the primary key cannot take null values. Because the null value is not 0, nor is it an empty string, it is an indeterminate value.
In a relational database system, once the primary key and entity integrity are defined, the DBMS will automatically maintain entity integrity rules. When inserting a row of data into the table, if the primary key is null or duplicate, the system will refuse to accept the inserted erroneous data and issue an error warning.
2. Referential integrity
1. Definition of
referential integrity Referential integrity means that the value of the foreign key must be the valid value of the primary key of the referenced table, or "null value".
If there is a value for the foreign key, this value must be a valid value for the primary key of the referenced table. In other words, the foreign key can have no value, but it is not allowed to be an invalid value. When a referential integrity constraint is set between two tables, the DBMS will automatically refuse to perform operations that violate
referential integrity. Two options for referential integrity
Some DBMS systems also provide two referential integrity options, namely " Cascading update related fields "and" cascading delete related records "are used to deal with the special requirements that allow deleting (or updating) records in the parent table under referential integrity constraints.
◇ Cascade delete related record option
The function of this option is called cascade delete. When deleting a record (row) in the parent table, all rows in the child table that match the primary key value of the deleted record will also be deleted.
◇ Cascade update related field options
This imagined function is called cascading update. When a primary key value in the parent table is updated, all foreign key values ​​corresponding to the primary key value in the child table will be updated at the same time.
3. User-defined integrity
All relational databases should support integrity and referential integrity, which are conditions that relational databases must meet. In addition, in order to meet the special requirements of various application environments, many database systems also provide multiple user-defined integrity functions. User-defined integrity is a constraint for a specific database.

Published 186 original articles · Likes 26 · Visits 20,000+

Guess you like

Origin blog.csdn.net/G_whang/article/details/105445553