Integrity Constraints
Integrity Constraints
1. Domain Constraint
2. Entity Constraint
3. Referential Integrity Constraint
4. Key Constraint
Domain Constraint
In the above student's table, the value A in the last row last column
violates the domain integrity constraint because the Class attribute
contains only integer values while A is a character.
Example:
ID Name Salary
1101 Jackson 40000
1102 Harry 60000
1103 Steve 80000
1104 Ash 1800000
James 36000
In the above employee's table, we can see that the ID column is the
primary key and contains a null value in the last row which violates the
entity integrity constraint.
Example:
Consider an Employee and a Department table where Dept_ID acts as a
foreign key between the two tables
Employees Table
Department Table
Dept_ID Dept_Name
1 Sales
2 HR
3 Technical
Key constraint
Keys are the set of entities that are used to identify an entity within its
entity set uniquely. There could be multiple keys in a single entity set,
but out of these multiple keys, only one key will be the primary key. A
primary key can only contain unique and not null values in the relational
database table.
Example:
The last row of the student's table violates the key integrity constraint
since Roll No 102 is repeated twice in the primary key column. A
primary key must be unique and not null therefore duplicate values are
not allowed in the Roll No column of the above student's table.