Database Integrity Concept and Integrity Constraints


What is database integrity (DB Integrity):

Database integrity refers to a characteristic of the DB that the DBMS should guarantee: correctness, validity, and consistency under any circumstances

  • Generalized integrity: semantic integrity, concurrency control, security control, DB failure recovery, etc.
  • Integrity in a narrow sense: refers to semantic integrity. DBMS usually has special integrity management mechanisms and procedures to deal with semantic integrity issues

Why does it cause database integrity problems?

  • Improper database operations, such as input errors, operation errors, program processing errors, etc.
  • Prevent and avoid the appearance of unreasonable data in the database
  • The DBMS should automatically prevent the unreasonable semantics in the DB as much as possible. If the DBMS cannot automatically prevent it, the application programmers and users need to be careful when operating the database. Every SQL statement written should consider whether it conforms to the semantic integrity. This workload is very heavy, so as much as possible should be left to the DBMS


Database Integrity Classification:

Sort by constraint object :

  • Domain integrity constraints: imposed on a column, the constraints are judged whether a candidate value to be updated on a given column is acceptable. This is done in isolation
  • Relational integrity constraints: imposed on a relation/table, to judge whether a candidate tuple to be updated on a given table is acceptable or not, or to determine whether several tuples in one relation and tuples in another relation are acceptable. Whether the connection between several tuples is acceptable for constraint judgment

Sort by constraint source :

  • Structural constraints: constraints from the model, such as functional dependency constraints, primary key constraints (entity integrity), foreign key constraints (referential integrity), only care about whether the values ​​are equal or not, whether to allow null values, etc.
  • Content constraints: constraints from users, such as user-defined integrity, care about the value range of tuples or attributes, for example, the value of the Sage attribute of the Student table is between 15 and 40 years old, etc.

Sort by constraint state :

  • Static constraints: constraints that require DB to satisfy at any time, such as Sage should satisfy greater than 0 and less than 120 at any time
  • Dynamic constraints: constraints that should be satisfied when the DB is required to change from one state to another, such as wages can only be increased, not decreased

There are integrity requirements in the relational model:

  • entity integrity
  • referential integrity
  • User Defined Integrity

General form of integrity constraints/rules:

  • Datasets (O): Objects of Constraints? Column, multicolumn (tuple), collection of tuples
  • Predicate Condition (P): What kind of constraints?
  • Trigger Condition (A): When to check?
  • Response Action (R): What to do when not satisfied?


How does a DBMS automatically guarantee integrity?

DBMS allows users to define some integrity constraint rules (defined by SQL-DDL)

When there is a DB update operation, the DBMS automatically checks according to the integrity constraints to ensure that the update operation complies with semantic integrity




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325831066&siteId=291194637