DEV Community

Mujahida Joynab
Mujahida Joynab

Posted on

Integrity Constraints (domain, entity, referential)

Integrity constraints are rules that ensure the quality, consistency, and validity of data in a database.

🔹 1. Domain Constraints
Apply to attributes (columns).

Restrict the type or format of data values.

Examples:

age → must be an integer and ≥ 0

name → only alphabetic characters

mobile → must match a specific pattern (e.g., 11 digits)

🔹 2. Entity Integrity
Ensures each row (tuple) can be uniquely identified.

A Primary Key:

Must be unique

Must be NOT NULL

💡 No two rows can have the same primary key, and it cannot be missing.

🔹 3. Referential Integrity
Maintains consistency between related tables.

A foreign key in one table must refer to a valid primary key in another.

💡 Ensures that relationships between tables remain valid (e.g., no orphan records).

  1. Key Constraints Attributes that are uniquely identifying.

Types:

Candidate Key: A set of minimal attributes that can uniquely identify a tuple.

Primary Key: Chosen from candidate keys.

Unique Key: Enforces uniqueness but allows NULL.

🔹 Why Use Integrity Constraints?
Enforce business rules directly in schema.

Prevent bad data entry at the database level.

Improve data reliability and system robustness.

Top comments (0)