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).
- 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)