Surrogate Key

Context: FIT2094_MOC, FIT3003_MOC · a system-generated artificial Primary Key · in FIT2094 added only at the logical stage with the natural key kept via a unique constraint; in FIT3003 it is the PK of a dimension table, implemented as a sequence

Quick Revision

  • 🎯 Objective: a system-generated meaningless PK replacing a natural key ➔ simplifies composite keys (FIT2094) and gives every dimension record one local identifier (FIT3003).
  • 📦 Core Components: added only logically ➔ natural key kept via UNIQUE constraint | warehouse form ➔ create sequence .nextval.
  • ⚡ Key Constraint: without the UNIQUE constraint, the natural-key business rule is lost — and in a warehouse, if the operational PK is already unique across systems, the surrogate is optional.

📝 Core

1. The Surrogate

  • Definition ➔ a system-generated, business-meaningless identifier used as Primary Key in place of a natural key.
  • Stage ➔ only at logical design — never conceptual.

2. Why Add One

  • Composite keys are unwieldy ➔ an index per key attribute, more storage, slower, bloats child FKs.
  • Single numeric id ➔ one easy-to-manage identifier.

3. Protect the Natural Key

  • Manual add ➔ new PK attribute (et_no); don’t use a modeller’s auto option.
  • Former composite → attributes ➔ enforce UNIQUE (NOT NULL) on the natural key.

4. In the Data Warehouse (FIT3003 Ch9)

  • Scope is one dimension ➔ a surrogate key is a unique identification for each record in a dimension table and its PK; it is local to that dimension, not global to the warehouse.
  • Implementation is a sequence ➔ not hand-typed update … where statements; the same Seq_ID idiom keys a junk dimension.
  • The fact must be re-keyed too ➔ the staged TempFact holds the natural values, so it gains the surrogate column and is filled from the dimension before the final group by.
  • Trigger-filled alternative (W11) ➔ a BEFORE INSERT … FOR EACH ROW trigger runs select seq.nextval into :new.ID from dual, so every inserted row is keyed with no update pass ➔ Database Triggers (Oracle).
  • It is optional, not mandatory ➔ if the operational PK is already unique across all source systems, adding a surrogate buys nothing in the warehouse.
  • It does not rescue a thin dimension ➔ SexDim(SexID, Sex) still has nothing to look up; what earns a one-column dimension its place is a description ➔ One-Attribute Dimensions.

⚙️ Core Implementation

🔹 EMPLOYEE_TRAINING with surrogate (FIT2094)

🔹 SuburbDIM with a sequence surrogate (FIT3003)

⚖️ Core Decision Matrix

AspectNatural PKSurrogate PK
meaningbusiness rulesnone
sizecompositesingle numeric
child FKsbloatedsimple
natural keyis the PKkept as UNIQUE (FIT2094) / kept as an attribute of the dimension (FIT3003)
warehouse necessitysufficient when already globally uniqueneeded when source systems collide or the key is composite

When It Flips: the natural key encodes the Normalisation rules, so it must be kept and enforced; the surrogate only replaces it as the PK, not the rule. Added at the end of logical design, after 3NF and ER mapping. In a warehouse the flip is different: surrogates become optional the moment every source system's PK is already unique across systems.

📊 Exam Execution Trace

Manual Execution Trace

Adding a surrogate:

Step / StateActionResult
0 (Init)composite natural PKunwieldy
1add et_no PKsingle numeric id
2natural key → attributesneeds protection
3UNIQUE(natural key)rule preserved

Applied Exercise

Problem: After adding surrogate et_no, how is the natural key protected and why? Derivation Proof / Hand-Calculation Walkthrough:

Final Extracted Output: a UNIQUE (NOT NULL) constraint on the natural key preserves the business rule.

🧠 Active Recall