Open In App

Constraints on Relational Database Model

In modeling the design of the relational database we can put some restrictions like what values are allowed to be inserted in the relation, and what kind of modifications and deletions are allowed in the relation. These are the restrictions we impose on the relational database. 

In models like Entity-Relationship models, we did not have such features. Database Constraints can be categorized into 3 main categories: 



  1. Constraints that are applied in the data model are called Implicit Constraints.
  2. Constraints that are directly applied in the schemas of the data model, by specifying them in the DDL(Data Definition Language). These are called Schema-Based Constraints or Explicit Constraints.
  3. Constraints that cannot be directly applied in the schemas of the data model. We call these Application-based or Semantic Constraints.

So here we are going to deal with Implicit constraints

Relational Constraints

These are the restrictions or sets of rules imposed on the database contents. It validates the quality of the database. It validates the various operations like data insertion, updation, and other processes that have to be performed without affecting the integrity of the data. It protects us against threats/damages to the database. Mainly Constraints on the relational database are of 4 types



Types of Relational Constraints

Let’s discuss each of the above constraints in detail. 

1. Domain Constraints 

Example: 

EID       Name                   Phone                 
01 Bikash Dutta

123456789

234456678

Explanation: In the above relation, Name is a composite attribute and Phone is a multi-values attribute, so it is violating domain constraint. 

2. Key Constraints or Uniqueness Constraints

Example: 

EID       Name             Phone                      
01 Bikash 6000000009
02 Paul 9000090009
01 Tuhin 9234567892

Explanation: In the above table, EID is the primary key, and the first and the last tuple have the same value in EID ie 01, so it is violating the key constraint. 

3. Entity Integrity Constraints

Example: 

EID        Name             Phone              
01 Bikash 9000900099
02 Paul 600000009
NULL Sony 9234567892

Explanation: In the above relation, EID is made the primary key, and the primary key can’t take NULL values but in the third tuple, the primary key is null, so it is violating Entity Integrity constraints. 

4. Referential Integrity Constraints

Example:

EID        Name         DNO     
01 Divine 12
02 Dino 22
04 Vivian 14
DNO        Place          
12 Jaipur
13 Mumbai
14 Delhi

Explanation: In the above tables, the DNO of Table 1 is the foreign key, and DNO in Table 2 is the primary key. DNO = 22 in the foreign key of Table 1 is not allowed because DNO = 22 is not defined in the primary key of table 2. Therefore, Referential integrity constraints are violated here.

Advantages of Relational Database Model 

Disadvantages of the Relational Model

Conclusion

Relational database constraints are rules in a database model that help maintain the integrity and consistency of data. These rules include primary key constraints, unique constraints, foreign key constraints, check constraints, default constraints, not null constraints, multi-column constraints, etc. Relational database constraints help keep data accurate, maintain relationships, and avoid the insertion of wrong or inconsistent data.


Article Tags :