Integrity Constraints In DBMS

Integrity constraints are the set of rules used to maintain the quality information in a relational database.

Integrity constraints are used to guard the database against any accidental damages. Hence, integrity constraints ensures that the insertion, deletion and other processes on data are performed without affecting the data integrity.

Types of Integrity Constraints

types of integrity constraints

There are different types of integrity constraints in DBMS.

  • Domain Constraint
  • Referential Integrity Constraint
  • Entity Integrity Constraint
  • Key Constraint

Domain Constraint

A Domain constraint is said to be violated if the value of attribute is not appearing in the corresponding domain or the appearing value is not the appropriate data type.

Domain constraint specifies that the values of each attribute must be unique in each tuple.  This can be specified as data types which include standard data types integers, characters, Booleans, real numbers, variable length strings, etc.

domain constraint

Above table is not allowed because ‘E’ is not appropriate data type for age attribute.

Referential Integrity Constraint

A referential integrity constraint is applied between two tables.

Referential integrity constraint occurs when relation refers to a key attribute of a different or same relation. That key element must exist in any one of the tables.

referential constraint

In the above table primary keys of student table and course are used as foreign keys in marks table.

Entity Integrity Constraint

Entity integrity constraint states that the primary key value can not be NULL. Because a primary key values are used to identify specific tuples. If a primary key is NULL then that tuple can’t be identified. In a table attributes other than primary key can be NULL.

Entity integrity constraint

Above table is not allowed because a primary key can’t be a NULL value.

Key Constraint

Keys are the attributes used to identify an entity uniquely in an entity set.

An entity set can contain multiple key values, but one of that keys is primary key which is a unique identity of a tuple.

A primary can’t be duplicate value or a NULL.

key consraint

Above table is not allowed because duplication of primary key is not allowed.

Reference: Database Management Systems

Also Read: --> File system and DBMS difference  --> Data Models DBMS

constraints in dbms | key, domain & referential integrity |

FAQ?

What are the types of Integrity Constraints?

Domain Constraint
Referential Integrity Constraint
Entity Integrity Constraint
Key Constraint

Can a primary key contain duplicate values?

No, a primary key can’t contain a duplicate value

Leave a comment