Relational Constraints


[Previous] [Table of Contents] [Next]

Relational Constraints

There are three types of constraints on relational database that include:

1. —Domain Constraint

It specifies that each attribute in a relation must contain a value only from the corresponding domains.

—2. Key Constraint

This constraint states that the key attribute value in each tuple must be unique, i.e., no two tuples contain the same value for the key attribute. This is because the value of the primary key is used to identify the tuples in the relation.

3. —Integrity Constraint

Data Integrity means that the data should be accurate and consistent.  This is done by providing some checks or constraints.  These constraints are known as integrity constraints.  There are two types of integrity constraints: i) Entity Integrity Constraint ii) Referential Integrity Constraint

Entity Integrity Constraint:

It states that no primary key value can be null. This is because the primary key is used to identify individual tuple in the relation. So we will not be able to identify the records uniquely containing null values for the primary key attributes. This constraint is specified on one individual relation.

Referential Integrity Constraint

The referential integrity constraint is specified between two tables and it is used to maintain the consistency among rows between the two tables.

The rules are:
1. You can’t delete a record from a primary table if matching records exist in a related table.
2. You can’t change a primary key value in the primary table if that record has related records.
3. You can’t enter a value in the foreign key field of the related table that doesn’t exist in the primary key of the primary table.