Entity Integrity and Referential Integrity

Let us understand the concept of Entity Integrity and Referential Integrity. Before proceeding further, we recommend to read these article for better understanding:

Entity Integrity Constraint

Entity means any place, thing or person in database. An entity represents a real world object. Each table represents an entity and each row in a table is the instance of entity.
Entity Integrity constraint uniquely identifies each row in table. Primary key assures the entity integrity constraint is applied to a table.
It also states that value in primary key fields cannot be null.

For example, Let us take example of table Employee having columns: Emp_Id, Name, Address, Pincode, Passport_Number, Salary.

IT_Officer_004_01

Let’s say Emp_Id is primary key in the table. Thus from the definition of Entity Integrity, the value of Emp_Id cannot be null as it unique identifies an employee record in the table.

Thus no primary key column of any row in a table can have a null value.

Referential Integrity Constraint

Referential integrity constraint refers to relationship between the tables. The relationship between tables is established by using foreign keys. This constraint states that a foreign key must have a matching primary key in another table or must be null.

For example, let’s say we have table SC that tells us which student study in which class. We also have Student and Class tables.

Table SC

IT_Officer_003_02

Table Student
IT_Officer_003_05

Table Class
IT_Officer_003_06

  • The Student_Id in any row of the SC table corresponds to a Student_Id of the Student table.
  •     The Class_Id in any row of the SC table corresponds to a Class_Id of the Class table.

Thus every foreign key must contain a null value or a valid key reference in another table.

Download as PDF

Read next:  Normalization ››

« Back to Course page