Functional Dependencies (Part 1)
Data Anomalies
- Primary key of the table: (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→Name holds
- Conversely, multiple people can share the same name, so Name→NRIC in general
- Thus: NRIC→Name, but not Name→NRIC
- Example with three attributes: StudentID, Name, Address, PostalCode
- FD: StudentID→Name,Address,PostalCode
- Also, Address→PostalCode
- For attribute sets A<em>1,A</em>2,…,A<em>m and B</em>1,B<em>2,…,B</em>n:
- A<em>1A</em>2…A<em>m→B</em>1B<em>2…B</em>n
- Meaning: there do not exist two tuples that have the same values on A<em>1,A</em>2,…,A<em>m but different values on B</em>1,B<em>2,…,B</em>n
- Example: NRIC → 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→Department
- Category,Color→Price
- Price→Color
- Name→Color
- Department,Category→Name
- Color,Department→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 → ProductID (no shop sells more than one product)
- FD: ProductID → CustomerID (no two customers buy the same product)
- FD: (CustomerID,ProductID,ShopID,Date)→ 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→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→Address and Address→PostalCode, we can deduce NRIC→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⊆A then A→B
- Examples:
- NRIC,Name→NRIC
- StudentID,Name,Age→Name,Age
- ABCD→ABC
- Axiom of Augmentation: If A→B then AC→BC for any C
- Examples:
- If NRIC→Name, then NRIC,Age→Name,Age
- If NRIC,Salary,Weight→Name,Salary,Weight, then with Addr, NRIC,Salary,Weight,Addr→Name,Salary,Weight,Addr
- Axiom of Transitivity: If A→B and B→C then A→C
- Example: If NRIC→Addr and Addr→PostalCode, then NRIC→PostalCode
Reasoning with FD: Derivation Patterns
- Given A→B and BC→D, prove AC→D:
- Augmentation: AC→BC
- Transitivity: from AC→BC and BC→D derive AC→D
- Given A→B and D→C, prove AD→BC:
- Augmentation: AD→BD
- From AD→BD and reflexivity (since B subset of BD) get AD→B
- From D→C and augmentation get AD→AC
- From AD→AC and reflexivity get AD→C
- Combine AD→B and AD→C to obtain AD→BC
- Given A→C, AC→D, AD→B, prove A→B:
- A→C; Augment to A→AC
- With AC→D, by Transitivity get A→D
- Augment to A→AD; With AD→B, by Transitivity get A→B
An Intuitive, Stepwise FD Reasoning (closure approach)
- For 4 attributes A,B,C,D with B→D, DB→A, AD→C:
- Start with the activated set: B
- Apply B→D: B,D
- Apply DB→A: B,D,A
- Apply AD→C: B,D,A,C
- Conclude B→C (since C is in the closure)
Exercises: Derivation Practice with FDs
- Exercise 1: Given A→C,C→B,B→D,D→E,E→A, prove C→ABE
- Start with C; apply chain: C→B → {C,B}; B→D → {C,B,D}; D→E → {C,B,D,E}; E→A → {C,B,D,E,A}
- Thus A, B, and E are all in the closure, so C→ABE holds
- Exercise 2: Given C→D,AD→E,BC→E,E→A,D→B, prove C→A
- Start with C; C→D → {C,D}; D→B → {C,D,B}; BC→E with B and C → {C,D,B,E}; E→A → {C,D,B,E,A}; hence C→A
- Exercise 3: Given C→D,AD→E,BC→E,E→A,D→B,B→F, prove D→C
- Start with D; D→B → {D,B}; B→F → {D,B,F}
- No further derivations yield C; thus the given set does not imply D→C (closure of D is 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