Logo
Published on

Relational Integrity Constraints in DBMS – Types and Examples

✅ What Are Relational Integrity Constraints?

In a relational database, integrity constraints are rules that ensure your data stays accurate, consistent, and reliable. They prevent invalid or contradictory data from being added and help maintain the structure and trustworthiness of the database.

These rules are especially important for maintaining relationships between tables and avoiding issues like duplicate records, orphan data, or incorrect inputs.

🔍 Types of Integrity Constraints in DBMS

1. Domain Constraint

Defines the allowed values for an attribute. It includes data types and valid ranges.

Example: In a Student table, the CGPA attribute should only accept values between 0.0 and 4.0.

2. Entity Integrity Constraint

Ensures that every record has a unique, non-null primary key.

Example: In the Student table, Roll Number is the primary key and must never be null. This guarantees every student is uniquely identifiable.

3. Referential Integrity Constraint

Maintains consistency between related tables by ensuring foreign key values exist in the referenced table.

Example: Let’s say:

  • The Course table stores available courses (Course ID is the primary key).
  • The Student table contains Course ID as a foreign key.

Every course a student enrolls in must already exist in the Course table.

📌 Example Tables:

Course Table

Course IDCourse NameCredits
C101Introduction to DB3
C102Data Structures4
C103Algorithms3

Student Table

Student IDNameCourse ID
S001Alice SmithC101
S002Bob JohnsonC102
S003Carol WhiteC103
S004David BrownC101 ✅

The system will reject any student record referencing a nonexistent Course ID like C999.

4. Key Constraint (Uniqueness Constraint)

Enforces that specific fields (like primary or candidate keys) must hold unique values.

Example: The Email attribute in the Student table must be unique, so no two students can register with the same email.

5. Check Constraint

Applies custom rules to attribute values.

Example: A Check constraint can ensure that Age in the Student table is greater than or equal to 18, allowing only adult students to register.

📋 Summary Table of Constraints

Constraint TypePurposeExample
Domain ConstraintValidates attribute values fall in allowed rangeCGPA between 0.0 and 4.0
Entity IntegrityEnsures unique and non-null primary keysRoll Number in Student table
Referential IntegrityEnsures foreign key matches a valid primary keyCourse ID in Student must exist in Course
Key ConstraintAvoids duplicate values in key attributesUnique Email in Student table
Check ConstraintValidates custom conditionsAge ≥ 18

🧠 Why Integrity Constraints Matter

Without integrity constraints:

  • Data could become duplicated, inconsistent, or incomplete.
  • Relationships across tables might break.
  • Application logic would have to handle data validity manually.

These constraints automate data validation at the database level and are essential for any well-designed relational system.