Domain restricts the values of attributes in the relation and it is a constraint of the relational model. However, there are real –world semantics on data that cannot specified if used only with domain constraints. We need more specific ways to state what data values are/are not allowed and what format is suitable for an attributes. For example, the employee ID must be unique, the employee birthday is in the range [Jan 1, 1950, Jan 1, 2000]. Such information is provided in logical statements called integrity constraints.
There are several kinds of integrity constraints:
Entity Integrity – Every table requires a primary key. The primary key, nor any part of the primary key, can contain NULL values. This is because NULL values for the primary key means we cannot identify some rows. For example, in the EMPLOYEE table, Phone cannot be a key since some people may not have a phone.
Referential integrity – a foreign key must have a matching primary key or it must be null
This constraint is specified between two tables (parent and child); it maintains the correspondence between rows in these tables. It means the reference from a row in one table to other table must be valid. Examples of Referential integrity constraint:
- 3013 reads