Data Integrity

Context: FIT2094_MOC · three rules keeping relational data consistent · entity, referential, and column/domain integrity · enforced by the RDBMS

Quick Revision

  • 🎯 Objective: rules keeping relational data consistent ➔ entity / referential / column integrity.
  • 📦 Core Components: entity (PK) ➔ referential (FK) ➔ column/domain (attribute values).
  • ⚡ Key Constraint: declared once in the schema, enforced automatically on every DML operation.

📝 Core

1. The Three Rules

  • Entity integrity ➔ a Primary Key is unique + non-NULL for every tuple.
  • Referential integrity ➔ every foreign key matches a full PK or is NULL.
  • Column/domain integrity ➔ all values of an attribute from the same domain.

2. Each Guards a Level

  • Entity ➔ protects tuple identity (the PK).
  • Referential ➔ protects relationships (PK–FK links).
  • Column/domain ➔ protects attribute values (the domain).

⚙️ Core Implementation

🔹 The three rules as DDL

⚖️ Core Decision Matrix

RuleGuardsConstraint
entitytuple identityPK unique + non-NULL
referentialrelationshipsFK matches PK or NULL
column/domainattribute valuesone domain per attribute

When It Flips: constraints are part of the schema, so the DBMS rejects any insert/update/delete that would violate them — no per-operation application code. Referential integrity constrains deletes (block or cascade). NULL allowances are SQL/RDBMS features (classical algebra has none).

📊 Exam Execution Trace

Manual Execution Trace

Checking each rule:

Step / StateRuleExample violation
0 (Init)
1entityNULL/duplicate studentID
2referentialENROLMENT.student_id with no STUDENT
3columnAge = “twenty”

Applied Exercise

Problem: Why does entity integrity forbid a NULL or duplicate primary key? Derivation Proof / Hand-Calculation Walkthrough:

Final Extracted Output: PK must be unique + non-NULL to be a reliable handle on each tuple.

🧠 Active Recall