Integrity constraints are a set of rules that help to maintain the accuracy and consistency of data in a database. They are used to enforce business rules and prevent the insertion of invalid data into a database. Integrity constraints are added when designing the database schema and define the protocols that a tables data columns must follow. These constraints are applied on the table fields or relations to ensure that the overall validity, integrity, and consistency of the data present in the database table is maintained.
There are four types of integrity constraints in DBMS:
-
Domain Constraint: This constraint defines a set of values that are valid for an attribute. The value must be in the corresponding domain of the attribute.
-
Entity Constraint: This constraint states that the primary key cannot have a NULL value. This is because if the primary key is NULL, then we won’t be able to determine or identify the tuple in the relation.
-
Referential Integrity Constraint: This constraint ensures that the foreign key in one table matches the primary key in another table.
-
Key Constraint: This constraint ensures that each row/record in a database table is uniquely identified by the primary key.
Integrity constraints are useful in preventing any accidental damage to the database by an authorized user.