sign in
 
   
 
 
 
  Relational Constraints  
   
 

There are three types of constraints on relational database:
• Domain Constraints
• Primary Key Constraints
• Integrity Constraints

Domain Constraints:
It specifies that each attribute in a relation must contain an atomic value only from the corresponding domains. Domain constraint specifies the condition that we want to put on each instance of the relation. So the values that appear in each column must be drawn from the domain associated with that column.

Key Constraints:
This constraints 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.

Integrity Constraints:
There are two types of integrity constraints:
• Entity Integrity Constraint
• 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.

Referential Integrity Constraint:
It states that the tuple in one relation that refers to another relation must refer to an existing tuple in that relation. This constraint is specified on two relations, not necessarily distinct.

 
 
R
 
S
A#
B
C^
A1
B1
C1
A2
B2
C1
A3
B3
C2
A4
B4
C3
 
C#
E
C1
E1
C2
E2
C3
E3
 
  # identifies the primary key of a relation
^ identifies the foreign key of a relation
 
 
A referential constraint is the rule that the not null values of a foreign key are valid only if they have a match with the primary key of the associated parent table.
 
 
 
   
 
 
   
 
Database operations and constraint violations:

There are three basic operations to be performed on relations:

• Insertion
• Deletion
• Update


The INSERT Operation:

The insert operation allows us to insert a new tuple in a relation. When we try to insert a new record, then any of the following four types of constraints can be violated:

• Domain Constraint:
If the value given to an attribute lies outside the domain of that attribute.

• Key Constraint:
If the value of the key attribute in the new tuple t is the same as in the existing tuple in relation R.

• Entity Integrity Constraint:
If the primary key attribute value of new tuple is given as null.

• Referential Integrity Constraint:
If the value of the foreign key in t refers to a tuple that does not appear in the referenced relation.

If the insertion violates one or more constraints then
• Insertion can be rejected and the reason for rejection can also be explained to the user by DBMS

or

• Ask the user to correct the data and resubmit, also give the reason for rejecting the insertion.


The Deletion Operation:

Using the delete operation some existing records can be deleted from a relation. To delete some specific records from the database a condition is also specified, based on which records can be selected for deletion.


Constraints that can be violated during deletion:

Only one type of constraint can be violated during deletion, it is referential integrity constraint. It can occur when delete a record in the table where it is referenced by the foreign key of another table.

If the deletion violates referential integrity constraint, then

• Reject the deletion
• Attempt to cascade the deletion by deleting tuples that references the tuple that is being deleted.
• Change the value of referencing attribute that causes the violation.


The Update Operation:

Update operations are used for modifying database values.

The constraints violations faced by this operation are logically the same as the problem faced by Insertion and Deletion operations.