A Comprehensive Guide On Relational Integrity Constraints

Here, we will learn about the Integrity Constraints of the Relational Model in Database Management System. Integrity Constraints play an important role in the relational model of DBMS.

What is Relational Integrity Constraint?

Relational Integrity constraints are the set of rules and restrictions which are used to maintain the data consistency and integrity of a Relation (Table). Integrity constraints may be applied to each attribute of the table and the relationship between them. These rules prevent accidental damage to the relational database by the authorized users.
Following are the four main types of Relational Integrity Constraints in the Database Management System:
  1. Key Constraint
  2. Referential Integrity constraint
  3. Entity Integrity constraint
  4. Domain constraint

Key Constraint

A key constraint is that constraint which uniquely identifies the tuple of a relation. A Relation should have at least one key constraint. If any attribute is defined as a key constraint, the values are different for each tuple of that key attribute.
In the following Employee table, Employee_ID is a key attribute. In this attribute, no two values can have the same name. This attribute cannot have any Null value.

Referential Integrity Constraint

The referential integrity constraint is a type of constraint that exists between two tables for maintaining the data consistency in both the tables. This type of integrity constraint depends on the concept of Foreign key.
This constraint states that, if the foreign key of any table relates with the primary key of another table, then each value of the foreign key must exist in the Primary key attribute. And, any value of foreign key may be NULL.
Following are the two tables, whose names are Course and Student.
In the Student table, Course_ID is a foreign key.
In the Course table, Course_ID is a primary key.

 Entity Integrity Constraint

An entity integrity constraint states that the value of the primary key attribute cannot be NULL. The primary key attribute can’t be NULL because, it identifies each tuple of that relation, if any cell of the key attribute contains a NULL value, then that row cannot be accessed easily.
In the following table, Employee_ID is a primary key. This constraint states that Employee_ID cannot be NULL, because we cannot access the details of that employee whose ID is NULL.

Domain Constraint

Domain constraint is that constraint which defines the set of rules for an attribute of ‘Relation’. It specifies that the field accepts only those values which exist in the defined domain.
Domain Constraints are the user-defined data types such as Date, String, Integer, Currency, character, etc.
In the following Employee table, if we want to enter the salary in the whole number, then we can define the domain Integer on the Salary attribute. so the attribute accepts only whole numbers. It cannot accepts values like 25,000.11, ‘twenty-five thousand’, etc.

Leave a Comment