Constraints: Domain level constraints, Referential Constraints
In a database management system, constraints are rules that ensure data remains accurate and consistent. Domain level constraints focus on individual fields, while referential constraints manage the relationships between tables.

1. Domain Level Constraints
Domain constraints define the set of permissible values for an individual attribute (column). They act as a filter to ensure that only “legal” data enters a specific field.
- Data Type: The most basic domain constraint, requiring data to match a specific type (e.g., Integer, Varchar, Date).
- NOT NULL: Ensures a field must contain a value and cannot be left empty.
- CHECK Constraint: Enforces specific business rules or ranges (e.g.,
Age >= 18orPrice > 0).
2. Referential Constraints
Referential constraints (often implemented via Foreign Keys) ensure that relationships between different tables remain intact and synchronized.
- Foreign Key Rule: A value in a foreign key column must either match an existing Primary Key value in the parent table or be NULL.
- Consistency Actions: These define what happens when a parent record is changed:
- CASCADE: If a parent row is deleted/updated, related child rows are automatically deleted/updated.
- RESTRICT/NO ACTION: Prevents the deletion of a parent row if related child rows still exist.