Referential integrity is a relational database concept.This is the most common type of integrity constraint. This is used to manage the relationships between primary and foreign keys.
Referential integrity is best illustrated by an example.
Let's assume the department and employee entities have been implemented as tables in a relational database system.
When entering a new employee, the department in which they work needs to be specified. Department number is the foreign key in the employee table and the primary key in the department table.
In order to preserve the integrity of the data in the database there are a set of rules that need to be observed:
If inserting an employee in the employee table, the insertion should only be allowed if their department number exists in the department table
If deleting a department in the department table, the deletion should only be allowed if there are no employees working in that department
If changing the value of a department number in the department table, the update should only be allowed if there are no employees working in the department whose number is being changed
If changing the value of a department number in the employee table, the update should only be allowed if the new value exists in the department table
If any of the above is allowed to happen then we have data in an inconsistent state. The integrity of the data is compromised - the data does not make sense.