Referential integrity nuance: May a foreign key attribute be NULL and still satisfy the referential integrity constraint (assuming no additional NOT NULL rule and no conflicting business rule)?

Difficulty: Easy

Correct Answer: Correct

Explanation:


Introduction / Context:
Referential integrity (RI) ensures that when a foreign key (FK) references a parent table, the referenced parent row exists. Designers often ask whether NULLs are compatible with RI. Understanding how NULL interacts with FKs is fundamental for optional relationships, historical snapshots, and staged data loads.


Given Data / Assumptions:

  • We consider standard RI behavior in relational databases.
  • No additional constraint forces the FK column(s) to be NOT NULL.
  • The relationship may be optional, meaning a child row can exist without a defined parent reference.


Concept / Approach:
A NULL in a foreign key column indicates “unknown” or “not applicable.” In most DBMS products, a NULL FK neither passes nor fails a lookup; it is excluded from the RI check because there is no value to verify against the parent. Therefore, an FK may be NULL without violating RI, provided business rules allow it and the column is not declared NOT NULL. This is how optional relationships are modeled: the FK is nullable and, when present, must match an existing parent key value.


Step-by-Step Solution:

Define the relationship as optional by leaving the FK column nullable.When an FK value is present, the DBMS enforces a match to a parent key.When the FK is NULL, no parent is required and RI is not violated.If business rules mandate a parent, set the FK to NOT NULL and enforce insert order or use deferred constraints.


Verification / Alternative check:
Create a child row with a NULL FK in a test schema; observe that inserts succeed under RI, while non-NULL values that lack matching parents are rejected.


Why Other Options Are Wrong:

  • Incorrect: This ignores how NULL indicates no reference to validate.
  • Restrictions about denormalization, composite keys, or system type are irrelevant to the core rule.


Common Pitfalls:
Confusing business-mandated non-nullability with RI itself; assuming NULL equals a special key value, which it does not.


Final Answer:
Correct

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion