You are on page 1of 5

11/26/2018 Constraints in DBMS | Types of constraints in DBMS | Gate Vidyalay

Gate Vidyalay A temple of learning for GATE, NET, PSUs

Constraints in DBMS | Types of Constraints in DBMS


Akshay Singhal Database Management System

Constraints in DBMS-

The constraints or restrictions that are implemented on the database contents or on the database operations for ensuring the data correctness in the database are
called as relational constraints in DBMS.

Types of constraints in DBMS-

There are following 5 different types of relational constraints that are implemented on the database in DBMS-

1. Domain constraint
2. Tuple Uniqueness constraint
3. Key constraint
4. Entity Integrity constraint
5. Referential Integrity constraint

1. Domain constraint-

Domain constraint defines the domain of values i.e. the set of values which can be taken by the attribute.
Domain constraint also specifies that the values which an attribute take must be necessarily atomic values from its domain.

Example-
Student

STU_ID Name Age

S001 Akshay 20

S002 Abhishek 21

https://www.gatevidyalay.com/constraints-in-dbms-types-of-constraints-in-dbms/ 1/5
11/26/2018 Constraints in DBMS | Types of constraints in DBMS | Gate Vidyalay
S003 Shashank 20

S004 Rahul A

Here, value ‘A’ is not allowed because only integer values can be taken by the age attribute.

2. Tuple uniqueness constraint-

Tuple uniqueness constraint specifies that in any relation, all the tuples must be necessarily unique.

Example-
Student

STU_ID Name Age

S001 Akshay 20

S002 Abhishek 21

S003 Shashank 20

S004 Rahul 20

Here, this relation satisfies the tuple uniqueness constraint as here all the tuples are unique.

Student

STU_ID Name Age

S001 Akshay 20

S001 Akshay 20

S003 Shashank 20

S004 Rahul 20

Here, this relation does not satisfy the tuple uniqueness constraint as here all the tuples are not unique. (The first two tuples are same)

3. Key constraint-

Key constraint specifies that in any relation, all the values of the primary key must be unique and no value must be null.

Example-
Student

STU_ID Name Age

S001 Akshay 20

S001 Abhishek 21

S003 Shashank 20

https://www.gatevidyalay.com/constraints-in-dbms-types-of-constraints-in-dbms/ 2/5
11/26/2018 Constraints in DBMS | Types of constraints in DBMS | Gate Vidyalay
S004 Rahul 20

Here, this relation does not satisfy the key constraint as here the values of primary key are not unique.

4. Entity Integrity constraint-

Entity Integrity constraint specifies that in any relation, there must be no attribute of primary key which contains a null value as the presence of null value in
primary key would violate its uniqueness property.

Example-
Student

STU_ID Name Age

S001 Akshay 20

S002 Abhishek 21

S003 Shashank 20

Rahul 20

Here, this relation does not satisfy the entity integrity constraint as here the primary key contains a NULL value.

5. Referential Integrity constraint-

Referential Integrity constraint specifies that if a primary key of any relation has been referenced by the foreign key of some relation, then every value of that
foreign key must be available in the relation to which the primary key belongs or otherwise it must be null.
In other words, foreign key is allowed to take only those values which have been already taken by the primary key it refers to.
The relation which references the other relation is called as the referencing relation.
The relation which has been referenced is called as the referenced relation.
The referencing relation attribute which references the referenced relation’s primary key is called as the referencing attribute.
The attribute of the referenced relation which has been referenced by the referencing relation is called as the referenced attribute.

Note-

Referencing relation can also be called as the foreign table.


Referenced relation can also be called as the master table or primary table.

Important Results-

We can not insert any record into a referencing relation if the corresponding record does not exist in the referenced relation.
We can not delete or update the records of the referenced relation if the corresponding records exist in the referencing relation.

Example-

Consider the following two relations- ‘Student’ and ‘Department’.

Here, relation ‘Department’ references the relation ‘Student’.


https://www.gatevidyalay.com/constraints-in-dbms-types-of-constraints-in-dbms/ 3/5
11/26/2018 Constraints in DBMS | Types of constraints in DBMS | Gate Vidyalay

Student

STU_ID Name Dept_no

S001 Akshay D10

S002 Abhishek D10

S003 Shashank D11

S004 Rahul D14

Department

Dept_no Dept_name

D10 ASET

D11 ALS

D12 ASFL

D13 ASHS

Here, the relation ‘Student’ does not satisfy the referential integrity constraint as in relation ‘Department’, the department no. 14 has not been defined as a primary
key.

So, here the referential integrity constraint is violated.

How to handle the violation of referential integrity constraint?

It is very important to handle the violation of referential integrity constraint appropriately to ensure the correctness of the data in the database.
Here, the causes and ways to handle the violation of referential integrity constraint has been discussed.

Get more notes and other study material of Database Management System (DBMS).

Watch video lectures by visiting our YouTube channel LearnVidFun.

Summary

https://www.gatevidyalay.com/constraints-in-dbms-types-of-constraints-in-dbms/ 4/5
11/26/2018 Constraints in DBMS | Types of constraints in DBMS | Gate Vidyalay

Article Name Constraints in DBMS | Types of constraints in DBMS

Description Relational constraints are those constraints that are


implemented on the database contents for ensuring the
data correctness in the database. Types of constraints in
DBMS Domain constraint- Tuple Uniqueness constraint,
Key constraint, Entity Integrity constraint, Referential
Integrity constraint

Author Akshay Singhal

Publisher Name Gate Vidyalay

Publisher Logo

Liked this post? Share this article with your friends, classmates and colleagues-

https://www.gatevidyalay.com/constraints-in-dbms-types-of-constraints-in-dbms/ 5/5

You might also like