Relational Integrity
Relational Integrity
Definition
Relational integrity refers to the set of rules (integrity constraints) that a legal database instance must always satisfy so that the data remains accurate, consistent, and meaningful. The three foundational rules in the classical relational model are Domain Integrity, Entity Integrity, and Referential Integrity (additional user-defined/business constraints may also apply).
The Core Rules, using the running example
- Domain Integrity: every attribute value must belong to its declared domain — e.g.,
gpamust be a decimal in [0.0, 10.0]; storing"A+"ingpawould violate domain integrity. - Entity Integrity: no attribute that is part of a primary key may be NULL, and every tuple must be uniquely identifiable — e.g.,
idin Students can never be NULL or duplicated. - Referential Integrity: a foreign key value must either be NULL (if permitted) or match an existing primary key value in the referenced relation — e.g., if
Enrollments.student_idreferencesStudents.id, every enrollment must point to a genuinely existing student.
How this differs from "Relational Model Rules" (its closest sibling)
Relational Integrity is specifically about the constraint rules that keep DATA VALID (domain/entity/referential integrity plus optional business rules). Relational Model Rules (Codd's 12 Rules, the next topic) is a much broader term describing what makes an entire DBMS "truly relational" — integrity is just one piece (roughly Codd's Rule 10) of that larger checklist, which also covers things like systematic NULL treatment, catalog access, view updating, and distribution independence.
Edge Cases
- Referential integrity violations are commonly handled via
ON DELETE/ON UPDATEactions (CASCADE,SET NULL,RESTRICT) — the rule itself is always enforced, but its resolution strategy is configurable by the schema designer. - Domain integrity failures are usually caught automatically at insert/update time by the DBMS's type system (e.g., inserting a string into an integer column), but business-level domain restrictions (like "gpa must be ≥ 0") often require an explicit
CHECKconstraint. - A self-referencing foreign key (e.g., an
advisor_idin Students that referencesStudents.id) still must satisfy referential integrity — against the very same table.
Key Takeaways / Q&A
Q: Which integrity rule is violated if an Enrollments row has `student_id = 999` but no student with id 999 exists? A: Referential integrity.
Q: Which integrity rule is violated if a Students row has `id = NULL`? A: Entity integrity (the primary key can never be NULL).