Constraints in DBMS - Types of Constraints in DBMS - Gate Vidyalay
Constraints in DBMS - Types of Constraints in DBMS - Gate Vidyalay
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.
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
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.
Tuple uniqueness constraint specifies that in any relation, all the tuples must be necessarily unique.
Example-
Student
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
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
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.
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
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.
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-
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-
Student
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.
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).
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
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