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)