Functional Dependencies (Part 1)

Data Anomalies

  • Primary key of the table: (NRIC,PhoneNumber)(NRIC, PhoneNumber), a composite key
  • Anomalies arise due to a bad combination of attributes and redundancy
  • Types of anomalies demonstrated:
    • Redundancy: the same address value appears in multiple rows
    • Update anomaly: updating one address row leaves another unchanged
    • Deletion anomaly: deleting a row may remove needed information about another attribute
    • Insertion anomaly: cannot insert a new person if the primary-key constraint would require NULL values
  • Example table (Name, NRIC, PhoneNumber, HomeAddress):
    • Alice | 1234 | 67899876 | Jurong East
    • Alice | 1234 | 83848384 | Jurong East
    • Bob | 5678 | 98765432 | Pasir Ris
    • This illustrates that multiple rows share the same person (Alice) but different phone numbers

Normalization

  • Goal: remove anomalies by decomposing the table into smaller, well-structured relations
  • Decomposition example from the slide:
    • Original relation: (Name, NRIC, PhoneNumber, HomeAddress)
    • Decomposed into two relations:
    • R1(Name, NRIC, HomeAddress)
    • R2(NRIC, PhoneNumber)
  • Resulting data:
    • R1 tuples:
    • (Alice, 1234, Jurong East)
    • (Bob, 5678, Pasir Ris)
    • R2 tuples:
    • (1234, 67899876)
    • (1234, 83848384)
    • (5678, 98765432)
  • Effects of normalization:
    • Duplication is reduced (e.g., Alice’s address no longer duplicated)
    • Update anomalies eliminated (address stored in one place per NRIC)
    • Deletion anomalies eliminated (Bob’s phone can be removed without losing other data)
    • Insertion anomalies eliminated (you can insert an individual without a phone number)
  • Final normalized design examples from the slide:
    • Name NRIC HomeAddress
    • Alice | 1234 | Jurong East
    • Bob | 5678 | Pasir Ris
    • NRIC PhoneNumber
    • 1234 | 67899876
    • 1234 | 83848384
    • 5678 | 98765432

This Lecture: Functional Dependencies (FD) and Armstrong's Axioms

  • Topics covered in this lecture:
    • Data anomalies
    • Functional dependencies (FDs)
    • Armstrong's axioms for FD reasoning

Functional Dependencies (FD): Intuition and Examples

  • Intuition: to understand why certain attribute values correlate, causing anomalies
  • Example with two attributes: NRIC and Name
    • From real-world knowledge: NRIC uniquely identifies a person, so NRIC→NameNRIC \to Name holds
    • Conversely, multiple people can share the same name, so Name↛NRICName \not\to NRIC in general
    • Thus: NRIC→NameNRIC \to Name, but not Name→NRICName \to NRIC
  • Example with three attributes: StudentID, Name, Address, PostalCode
    • FD: StudentID→Name,Address,PostalCodeStudentID \to Name, Address, PostalCode
    • Also, Address→PostalCodeAddress \to PostalCode

Formal Definition of FD

  • For attribute sets A<em>1,A</em>2,…,A<em>mA<em>1, A</em>2, …, A<em>m and B</em>1,B<em>2,…,B</em>nB</em>1, B<em>2, …, B</em>n:
    • A<em>1A</em>2…A<em>m→B</em>1B<em>2…B</em>nA<em>1A</em>2\ldots A<em>m \to B</em>1B<em>2\ldots B</em>n
    • Meaning: there do not exist two tuples that have the same values on A<em>1,A</em>2,…,A<em>mA<em>1, A</em>2, \ldots, A<em>m but different values on B</em>1,B<em>2,…,B</em>nB</em>1, B<em>2, \ldots, B</em>n
  • Example: NRIC →\to Name expresses that no two persons with the same NRIC have different names

FD Examples (from the slides)

  • Example FD set in a sample table:
    • Category→DepartmentCategory \to Department
    • Category,Color→PriceCategory, Color \to Price
    • Price→ColorPrice \to Color
    • Name→ColorName \to Color
    • Department,Category→NameDepartment, Category \to Name
    • Color,Department→Name,PriceColor, Department \to Name, Price
  • Sample data (Name, Category, Color, Department, Price):
    • Gizmo | Gadget | Green | Toys | 49
    • Tweaker | Gadget | Black | Toys | 99
    • Gizmo | Stationary | Green | Office Supplies | 59

Where Do FDs Come From?

  • FD sources:
    • Common sense and knowledge about the real world
    • Application requirements and constraints
  • Purchase example: Purchase(CustomerID, ProductID, ShopID, Price, Date)
    • FD: ShopID →\to ProductID (no shop sells more than one product)
    • FD: ProductID →\to CustomerID (no two customers buy the same product)
    • FD: (CustomerID,ProductID,ShopID,Date)→(CustomerID, ProductID, ShopID, Date) \to Price (no shop sells the same product to the same customer on the same date at two different prices)
  • Notation for composite determinants: extCustomerID,ProductID,ShopID,Date→Priceext{CustomerID, ProductID, ShopID, Date} \to \text{Price}

Roadmap: Using FDs to Decide If a Table is Good

  • Plan:
    • Understand basic concepts (FDs)
    • Learn how to reason with FDs
    • Apply to normalization to build good designs
  • The goal is to decide whether tables are good or need normalization based on FD reasoning

Reasoning with FDs

  • Goal: derive new FDs from given ones using rules
  • Example: Given NRIC→AddressNRIC \to Address and Address→PostalCodeAddress \to PostalCode, we can deduce NRIC→PostalCodeNRIC \to PostalCode
  • Why derivations matter: helps decide whether a table is "bad" or "good" by revealing hidden FDs
  • Armstrong's Axioms provide a sound basis for FD reasoning (see next section)

Armstrong’s Axioms (the three basic rules)

  • Axiom of Reflexivity: If B⊆AB \subseteq A then A→BA \to B
    • Examples:
    • NRIC,Name→NRICNRIC, Name \to NRIC
    • StudentID,Name,Age→Name,AgeStudentID, Name, Age \to Name, Age
    • ABCD→ABCABCD \to ABC
  • Axiom of Augmentation: If A→BA \to B then AC→BCAC \to BC for any CC
    • Examples:
    • If NRIC→NameNRIC \to Name, then NRIC,Age→Name,AgeNRIC, Age \to Name, Age
    • If NRIC,Salary,Weight→Name,Salary,WeightNRIC, Salary, Weight \to Name, Salary, Weight, then with AddrAddr, NRIC,Salary,Weight,Addr→Name,Salary,Weight,AddrNRIC, Salary, Weight, Addr \to Name, Salary, Weight, Addr
  • Axiom of Transitivity: If A→BA \to B and B→CB \to C then A→CA \to C
    • Example: If NRIC→AddrNRIC \to Addr and Addr→PostalCodeAddr \to PostalCode, then NRIC→PostalCodeNRIC \to PostalCode

Reasoning with FD: Derivation Patterns

  • Given A→BA\to B and BC→DBC\to D, prove AC→DAC\to D:
    • Augmentation: AC→BCAC\to BC
    • Transitivity: from AC→BCAC\to BC and BC→DBC\to D derive AC→DAC\to D
  • Given A→BA\to B and D→CD\to C, prove AD→BCAD\to BC:
    • Augmentation: AD→BDAD\to BD
    • From AD→BDAD\to BD and reflexivity (since BB subset of BDBD) get AD→BAD\to B
    • From D→CD\to C and augmentation get AD→ACAD\to AC
    • From AD→ACAD\to AC and reflexivity get AD→CAD\to C
    • Combine AD→BAD\to B and AD→CAD\to C to obtain AD→BCAD\to BC
  • Given A→CA\to C, AC→DAC\to D, AD→BAD\to B, prove A→BA\to B:
    • A→CA\to C; Augment to A→ACA\to AC
    • With AC→DAC\to D, by Transitivity get A→DA\to D
    • Augment to A→ADA\to AD; With AD→BAD\to B, by Transitivity get A→BA\to B

An Intuitive, Stepwise FD Reasoning (closure approach)

  • For 4 attributes A,B,C,DA,B,C,D with B→DB\to D, DB→ADB\to A, AD→CAD\to C:
    • Start with the activated set: B{B}
    • Apply B→DB\to D: B,D{B, D}
    • Apply DB→ADB\to A: B,D,A{B, D, A}
    • Apply AD→CAD\to C: B,D,A,C{B, D, A, C}
    • Conclude B→CB \to C (since CC is in the closure)

Exercises: Derivation Practice with FDs

  • Exercise 1: Given A→C,C→B,B→D,D→E,E→AA \to C, C \to B, B \to D, D \to E, E \to A, prove C→ABEC \to ABE
    • Start with C{C}; apply chain: C→BC\to B → {C,B}; B→DB\to D → {C,B,D}; D→ED\to E → {C,B,D,E}; E→AE\to A → {C,B,D,E,A}
    • Thus AA, BB, and EE are all in the closure, so C→ABEC \to ABE holds
  • Exercise 2: Given C→D,AD→E,BC→E,E→A,D→BC \to D, AD \to E, BC \to E, E \to A, D \to B, prove C→AC \to A
    • Start with C{C}; C→DC\to D → {C,D}; D→BD\to B → {C,D,B}; BC→EBC \to E with BB and CC → {C,D,B,E}; E→AE \to A → {C,D,B,E,A}; hence C→AC \to A
  • Exercise 3: Given C→D,AD→E,BC→E,E→A,D→B,B→FC \to D, AD \to E, BC \to E, E \to A, D \to B, B \to F, prove D→CD \to C
    • Start with D{D}; D→BD\to B → {D,B}; B→FB\to F → {D,B,F}
    • No further derivations yield CC; thus the given set does not imply D→CD \to C (closure of DD is D,B,F{D,B,F})

Continuation

  • This content leads to Topic 2: Functional Dependencies (2) which continues the discussion on FDs and normalization

Practical and Ethical/Policy Notes

  • Copyright and usage: Course materials are for NTU students for educational purposes only; redistribution or reproduction without permission is prohibited. Follow institutional guidelines to avoid disciplinary or legal action.
  • Practical takeaway: Understanding FDs and Armstrong's axioms is essential for deciding when a table design is prone to anomalies and how to decompose it to achieve normalization and data integrity