14 - Functional Dependencies

3402 words
17 min read
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

# 14 - Functional Dependencies ## ๐ŸŽฏ Learning Objectives After reading this topic, you will be able to: - Define functional dependencies and explain why they matter - Apply Armstrong's axioms to derive implied FDs - Compute closure of a set of FDs (Fโบ) - Compute attribute closure (ฮฑโบ) to find keys - Check equivalenc...

14 - Functional Dependencies

๐ŸŽฏ Learning Objectives

After reading this topic, you will be able to:
  • Define functional dependencies and explain why they matter
  • Apply Armstrong's axioms to derive implied FDs
  • Compute closure of a set of FDs (Fโบ)
  • Compute attribute closure (ฮฑโบ) to find keys
  • Check equivalence of two FD sets
  • Find superkeys and candidate keys using attribute closure

๐Ÿ“‹ Prerequisites

๐Ÿ“– Core Content

14.1 Intuition: What Data Relationships Tell Us

A functional dependency (FD) describes a relationship between attributes in a relation. It says: If I know the value of attribute(s) X, I can determine the value of attribute(s) Y. Real-world examples:
  • {Aadhaar_number} โ†’ {name, DOB} โ€” If I know your Aadhaar number, I know your name and date of birth
  • {student_id} โ†’ {student_name} โ€” If I know your student ID, I know your name
  • {zip_code} โ†’ {city} โ€” If I know the zip code, I know the city Formally: Xโ†’YX \rightarrow Y (read as "X determines Y" or "Y is functionally dependent on X")
Why This Matters: FDs are the foundation of normalization โ€” the process of designing schemas that avoid data redundancy and anomalies. Understanding FDs is critical for good database design.

14.2 Formal Definition

Given relation RR, a functional dependency Xโ†’YX \rightarrow Y holds iff: For any two tuples t1t_1 and t2t_2 in RR:
ifย t1[X]=t2[X]ย thenย t1[Y]=t2[Y]\text{if } t_1[X] = t_2[X] \text{ then } t_1[Y] = t_2[Y]
In plain English: "Whenever two rows have the same X value, they must also have the same Y value." Example: In instructor(ID, name, dept_name, salary), the FD IDโ†’nameID \rightarrow name means: if two rows have the same ID, they MUST have the same name.

14.3 Trivial vs. Non-Trivial FDs

TypeDefinitionExampleAlways True?
TrivialXโ†’YX \rightarrow Y where YโІXY \subseteq XAโ†’AA \rightarrow A , ABโ†’AAB \rightarrow AYes
Non-trivialYโŠˆXY \nsubseteq XIDโ†’nameID \rightarrow nameNo (depends on data)
Completely non-trivialXโˆฉY=โˆ…X \cap Y = \emptysetIDโ†’nameID \rightarrow nameNo
Trivial FDs are always true โ€” they convey no useful information.

14.4 Armstrong's Axioms

Armstrong's axioms are a set of inference rules for deriving new FDs from existing ones. They're sound (every derived FD is true) and complete (every implied FD can be derived).
RuleNameFormal DefinitionExample
1ReflexivityIf YโІXY \subseteq X , then Xโ†’YX \rightarrow YABโ†’AAB \rightarrow A
2AugmentationIf Xโ†’YX \rightarrow Y , then XZโ†’YZXZ \rightarrow YZIf Aโ†’BA \rightarrow B , then ACโ†’BCAC \rightarrow BC
3TransitivityIf Xโ†’YX \rightarrow Y and Yโ†’ZY \rightarrow Z , then Xโ†’ZX \rightarrow ZIf Aโ†’BA \rightarrow B and Bโ†’CB \rightarrow C , then Aโ†’CA \rightarrow C

Derived Rules

RuleDerivationExample
UnionIf Xโ†’YX \rightarrow Y and Xโ†’ZX \rightarrow Z , then Xโ†’YZX \rightarrow YZAโ†’BA \rightarrow B and Aโ†’CA \rightarrow C โ†’ Aโ†’BCA \rightarrow BC
DecompositionIf Xโ†’YZX \rightarrow YZ , then Xโ†’YX \rightarrow Y and Xโ†’ZX \rightarrow ZAโ†’BCA \rightarrow BC โ†’ Aโ†’BA \rightarrow B and Aโ†’CA \rightarrow C
PseudotransitivityIf Xโ†’YX \rightarrow Y and WYโ†’ZWY \rightarrow Z , then WXโ†’ZWX \rightarrow ZAโ†’BA \rightarrow B and CBโ†’DCB \rightarrow D โ†’ CAโ†’DCA \rightarrow D

14.5 Closure of FD Sets (Fโบ)

The closure of a set of FDs FF, denoted F+F^+, is the set of ALL FDs that can be derived from FF using Armstrong's axioms. Example: Given F={Aโ†’B,Bโ†’C}F = \{A \rightarrow B, B \rightarrow C\}, find F+F^+:
  1. Start with F: Aโ†’BA \rightarrow B, Bโ†’CB \rightarrow C
  2. By transitivity: Aโ†’CA \rightarrow C
  3. By reflexivity: Aโ†’AA \rightarrow A, Bโ†’BB \rightarrow B, Cโ†’CC \rightarrow C, ABโ†’AAB \rightarrow A, etc.
  4. By augmentation: ABโ†’BAB \rightarrow B, ABโ†’BCAB \rightarrow BC, ACโ†’BCAC \rightarrow BC, etc.
  5. By union/decomposition: Aโ†’BCA \rightarrow BC (from Aโ†’BA \rightarrow B and Aโ†’CA \rightarrow C)
  6. Continue until no new FDs can be derived F+F^+ can be very large โ€” up to 2n2^n FDs for n attributes. That's why we use attribute closure instead.

14.6 Attribute Closure (ฮฑโบ)

Instead of computing F+F^+ (all FDs), we compute the attribute closure of a set of attributes ฮฑ\alpha: the set of ALL attributes that can be determined by ฮฑ\alpha. Algorithm:
pseudo
attribute_closure(ฮฑ, F):
    result = ฮฑ
    while result changes:
        for each FD X โ†’ Y in F:
            if X โІ result:
                result = result โˆช Y
    return result

Worked Example: Attribute Closure

Given R(A,B,C,D,E)R(A, B, C, D, E) and F={Aโ†’BC,CDโ†’E,Bโ†’D}F = \{A \rightarrow BC, CD \rightarrow E, B \rightarrow D\} Compute A+A^+:
  1. result = {A}
  2. Aโ†’BCA \rightarrow BC: A โІ result? Yes โ†’ result = {A, B, C}
  3. Bโ†’DB \rightarrow D: B โІ result? Yes โ†’ result = {A, B, C, D}
  4. CDโ†’ECD \rightarrow E: CD โІ result? Yes โ†’ result = {A, B, C, D, E}
  5. No more changes. A+=A,B,C,D,EA^+ = {A, B, C, D, E} (all attributes!) Since A+A^+ contains all attributes, AA is a superkey.

14.7 Using Attribute Closure

Finding Candidate Keys

Method:
  1. Find attributes that never appear on the RHS of any FD โ€” they MUST be in every candidate key
  2. Compute closure of these mandatory attributes
  3. If closure covers all attributes, they form a candidate key
  4. If not, add one attribute at a time and recompute Example: R(A,B,C,D,E)R(A, B, C, D, E) with F={Aโ†’B,BCโ†’D,Dโ†’E}F = \{A \rightarrow B, BC \rightarrow D, D \rightarrow E\} Step 1: Find mandatory attributes:
  • Attributes not on RHS: A,CA, C (A appears only on LHS; C appears on LHS but never on RHS) Step 2: Compute {A,C}+\{A, C\}^+:
  • result = {A, C}
  • Aโ†’BA \rightarrow B: A โІ result โ†’ result = {A, B, C}
  • BCโ†’DBC \rightarrow D: BC โІ result โ†’ result = {A, B, C, D}
  • Dโ†’ED \rightarrow E: D โІ result โ†’ result = {A, B, C, D, E}
  • {A,C}+\{A, C\}^+ = ALL attributes! Step 3: {A,C}\{A, C\} is a candidate key (can we remove A? No, C+=CC^+ = {C}. Can we remove C? No, A+=A,Bโ‰ RA^+ = {A, B} \neq R.) Result: Candidate key = {A,C}\{A, C\}

Checking if an FD Holds

To check if Xโ†’YX \rightarrow Y holds in FF:
  1. Compute X+X^+ using F
  2. If YโІX+Y \subseteq X^+, then Xโ†’YX \rightarrow Y holds Example: Does ABโ†’EAB \rightarrow E hold in F={Aโ†’B,BCโ†’D,Dโ†’E}F = \{A \rightarrow B, BC \rightarrow D, D \rightarrow E\}?
  3. Compute {A,B}+\{A, B\}^+:
    • result = {A, B}
    • No FD applies (Aโ†’B applies but B is already there)
    • Wait: BCโ†’DBC \rightarrow D needs C, which isn't in result
    • {A,B}+=A,B\{A, B\}^+ = {A, B}
  4. E โˆ‰ {A, B}, so ABโ†’EAB \rightarrow E does NOT hold.

14.8 Equivalence of FD Sets

Two FD sets F1F_1 and F2F_2 are equivalent if F1+=F2+F_1^+ = F_2^+ (they have the same closure). Algorithm to check equivalence:
  1. For each FD Xโ†’YX \rightarrow Y in F1F_1, check if it holds in F2F_2 (using attribute closure with F2F_2)
  2. For each FD Xโ†’YX \rightarrow Y in F2F_2, check if it holds in F1F_1
  3. If all hold, F1F_1 and F2F_2 are equivalent Example: F1={Aโ†’B,Bโ†’C}F_1 = \{A \rightarrow B, B \rightarrow C\} F2={Aโ†’B,Aโ†’C}F_2 = \{A \rightarrow B, A \rightarrow C\} Check Aโ†’CA \rightarrow C in F1F_1: A+A^+ using F1F_1 = {A, B, C}. C โІ A+A^+ โœ“ Check Bโ†’CB \rightarrow C in F2F_2: B+B^+ using F2F_2 = {B}. C โˆ‰ B+B^+ โœ— F1F_1 and F2F_2 are NOT equivalent.

14.9 Worked Examples

Example 1: Finding Superkeys from Attribute Closure

Given R(A,B,C,D,G)R(A, B, C, D, G) and F={Aโ†’BCD,BCโ†’D,Bโ†’D,Dโ†’A}F = \{A \rightarrow BCD, BC \rightarrow D, B \rightarrow D, D \rightarrow A\} Prove AGAG is a superkey:
  • Compute {A,G}+\{A, G\}^+:
    • result = {A, G}
    • Aโ†’BCDA \rightarrow BCD: A โІ result โ†’ result = {A, B, C, D, G}
    • All attributes covered! {A,G}+\{A, G\}^+ = R
  • Therefore, AGAG is a superkey.

Example 2: First way to find candidate keys

R(A,B,C,D)R(A, B, C, D) with F={Aโ†’BCD,Dโ†’A}F = \{A \rightarrow BCD, D \rightarrow A\} Step 1: Attributes not on RHS: C appears on RHS of none โ†’ C is mandatory. Actually C doesn't appear on LHS of any FD, and isn't on RHS... Let me check:
  • Aโ†’BCD means A determines B,C,D
  • Dโ†’A means D determines A
  • C is never on RHS and never on LHS So C must be in every candidate key. Step 2: Compute {C}+\{C\}^+: just {C}. Not all attributes. Step 3: Try {C,A}+\{C, A\}^+:
  • result = {C, A}
  • Aโ†’BCDA \rightarrow BCD โ†’ result = {A, B, C, D} = R
  • {C,A}\{C, A\} is a superkey. Is it minimal? If we remove C, A+=A,B,C,D=RA^+ = {A, B, C, D} = R, so A alone is sufficient. If we remove A, C+=CC^+ = {C}. Wait, let me re-examine. A is on LHS, not on RHS... Actually A is never on RHS. So both A and C are mandatory? Let me check again: F={Aโ†’BCD,Dโ†’A}F = \{A \rightarrow BCD, D \rightarrow A\} Attributes on RHS: B, C, D, A (from Dโ†’A) Attributes NOT on RHS: (none โ€” A appears on RHS via Dโ†’A) Let me compute all candidate keys:
  • Compute D+D^+:
    • result = {D}
    • Dโ†’AD \rightarrow A โ†’ {D, A}
    • Aโ†’BCDA \rightarrow BCD โ†’ {A, B, C, D} = R
    • So D is a candidate key.
  • Compute A+A^+:
    • result = {A}
    • Aโ†’BCDA \rightarrow BCD โ†’ {A, B, C, D} = R
    • So A is a candidate key. Candidate keys: {A} and {D}.

14.10 Tracing Table: Systematic Attribute Closure

The attribute closure algorithm is best understood with a tracing table. Let's work through a complex example. Given: R(A,B,C,D,E,G)R(A, B, C, D, E, G) and F={Aโ†’BCD,BCโ†’DE,Bโ†’D,Dโ†’A}F = \{A \rightarrow BCD, BC \rightarrow DE, B \rightarrow D, D \rightarrow A\} Compute AG+AG^+:
StepResultFD CheckedFD Applies?New Attributes
1{A, G}โ€”โ€”โ€”
2{A, G}Aโ†’BCDA \rightarrow BCDYes (AโІ{A,G})B, C, D
3{A, B, C, D, G}BCโ†’DEBC \rightarrow DEYes (BCโІresult)E
4{A, B, C, D, E, G}Bโ†’DB \rightarrow DYes, but D already presentโ€”
5{A, B, C, D, E, G}Dโ†’AD \rightarrow AYes, but A already presentโ€”
6{A,B,C,D,E,G}=R\{A, B, C, D, E, G\} = RDoneโ€”All attributes!
Result: AG+=RAG^+ = R, therefore AGAG is a superkey.

14.11 Complete Example: Finding All Candidate Keys

Given: R(A,B,C,D,E,G)R(A, B, C, D, E, G) and F={ABโ†’CD,Cโ†’E,Eโ†’B,Dโ†’G}F = \{AB \rightarrow CD, C \rightarrow E, E \rightarrow B, D \rightarrow G\} Step 1: Identify mandatory attributes โ€” those that never appear on RHS.
AttributeAppears on RHS?Mandatory in CK?
ANo (only in ABโ†’CD LHS)Yes
BYes (Eโ†’B)No
CYes (ABโ†’CD)No
DYes (ABโ†’CD)No
EYes (Cโ†’E)No
GYes (Dโ†’G)No
A MUST be in every candidate key. Step 2: Compute {A}+\{A\}^+:
  • result = {A}
  • ABโ†’CDAB \rightarrow CD: needs B (not in result) โœ—
  • Cโ†’EC \rightarrow E: needs C โœ—
  • Eโ†’BE \rightarrow B: needs E โœ—
  • Dโ†’GD \rightarrow G: needs D โœ—
  • {A}+={A}\{A\}^+ = \{A\} โ€” not a superkey. Step 3: Add one attribute at a time. Try {A,B}\{A, B\}:
StepResultFDNew
1{A, B}โ€”โ€”
2{A, B}ABโ†’CDAB \rightarrow CDC, D
3{A, B, C, D}Cโ†’EC \rightarrow EE
4{A, B, C, D, E}Eโ†’BE \rightarrow BB (already)
5{A, B, C, D, E}Dโ†’GD \rightarrow GG
6{A, B, C, D, E, G} = RDoneโœ“
{A,B}+=R\{A, B\}^+ = R. CK found: {A,B}\{A, B\}. Try {A,C}\{A, C\}:
StepResultFDNew
1{A, C}โ€”โ€”
2{A, C}Cโ†’EC \rightarrow EE
3{A, C, E}Eโ†’BE \rightarrow BB
4{A, B, C, E}ABโ†’CDAB \rightarrow CDD
5{A, B, C, D, E}Dโ†’GD \rightarrow GG
6{A, B, C, D, E, G} = RDoneโœ“
{A,C}+=R\{A, C\}^+ = R. CK found: {A,C}\{A, C\}. Try {A,D}\{A, D\}:
StepResultFDNew
1{A, D}โ€”โ€”
2{A, D}Dโ†’GD \rightarrow GG
3{A, D, G}No other FD appliesโ€”
{A,D}+={A,D,G}โ‰ R\{A, D\}^+ = \{A, D, G\} \neq R. Not a superkey. Try {A,E}\{A, E\}:
StepResultFDNew
1{A, E}โ€”โ€”
2{A, E}Eโ†’BE \rightarrow BB
3{A, B, E}ABโ†’CDAB \rightarrow CDC, D
4{A, B, C, D, E}Dโ†’GD \rightarrow GG
5{A, B, C, D, E, G} = RDoneโœ“
{A,E}+=R\{A, E\}^+ = R. CK found: {A,E}\{A, E\}. Try {A,G}\{A, G\}:
StepResultFDNew
1{A, G}โ€”โ€”
2{A, G}No FD has A or G alone on LHSโ€”
{A,G}+={A,G}โ‰ R\{A, G\}^+ = \{A, G\} \neq R. Not a superkey. Candidate keys: {A,B}\{A, B\}, {A,C}\{A, C\}, {A,E}\{A, E\} Superkey count: With 6 attributes, three CKs of size 2, all sharing A: =26โˆ’2+26โˆ’2+26โˆ’2โˆ’26โˆ’3โˆ’26โˆ’3โˆ’26โˆ’3+26โˆ’4= 2^{6-2} + 2^{6-2} + 2^{6-2} - 2^{6-3} - 2^{6-3} - 2^{6-3} + 2^{6-4} =16+16+16โˆ’8โˆ’8โˆ’8+4=28= 16 + 16 + 16 - 8 - 8 - 8 + 4 = 28 superkeys

14.12 Practice: Attribute Closure Walkthrough

Problem: Given F={Aโ†’B,ACโ†’D,Bโ†’C,Dโ†’E}F = \{A \rightarrow B, AC \rightarrow D, B \rightarrow C, D \rightarrow E\}, compute {A}+\{A\}^+, {B}+\{B\}^+, {C}+\{C\}^+, and {A,C}+\{A, C\}^+. {A}+\{A\}^+ :
  1. result = {A}
  2. Aโ†’BA \rightarrow B โ†’ {A, B}
  3. Bโ†’CB \rightarrow C โ†’ {A, B, C}
  4. ACโ†’DAC \rightarrow D โ†’ {A, B, C, D}
  5. Dโ†’ED \rightarrow E โ†’ {A, B, C, D, E}
  6. Done. {A}+={A,B,C,D,E}\{A\}^+ = \{A, B, C, D, E\} {B}+\{B\}^+ :
  7. result = {B}
  8. Bโ†’CB \rightarrow C โ†’ {B, C}
  9. No other FD applies (A not in result)
  10. {B}+={B,C}\{B\}^+ = \{B, C\} {C}+\{C\}^+ :
  11. result = {C}
  12. No FD has C alone on LHS (ACโ†’D needs A)
  13. {C}+={C}\{C\}^+ = \{C\} {A,C}+\{A, C\}^+ :
  14. result = {A, C}
  15. Aโ†’BA \rightarrow B โ†’ {A, B, C}
  16. Bโ†’CB \rightarrow C โ†’ {A, B, C} (C already there)
  17. ACโ†’DAC \rightarrow D โ†’ {A, B, C, D}
  18. Dโ†’ED \rightarrow E โ†’ {A, B, C, D, E}
  19. Done. {A,C}+={A,B,C,D,E}\{A, C\}^+ = \{A, B, C, D, E\} Check: Is {A,C}\{A, C\} a candidate key? {A,C}+=R\{A, C\}^+ = R. Is it minimal?
  • Remove A: {C}+={C}โ‰ R\{C\}^+ = \{C\} \neq R โœ“ A needed
  • Remove C: {A}+={A,B,C,D,E}=R\{A\}^+ = \{A, B, C, D, E\} = R! So A alone is a candidate key.
  • Final CK: {A}\{A\} only.
ConceptDescriptionFormula
Functional DependencyX determines YXโ†’YX \rightarrow Y
Trivial FDY is subset of XYโІXY \subseteq X
Attribute ClosureAll attributes determined by ฮฑฮฑ+\alpha^+
Closure of FAll FDs derivable from FF+F^+
Candidate KeyMinimal superkeyAny ฮฑ where ฮฑ+=R\alpha^+ = R and no proper subset has closure = R

โš ๏ธ Common Pitfalls

Pitfall 1: Thinking FDs are "One-to-One Mappings"

The Mistake: "X โ†’ Y means X maps to a unique Y like a function." Why It's Wrong: That's actually correct for our purposes, but students confuse it with "every X maps to exactly one Y" (which is always true in relations โ€” each attribute has one value per tuple). The FD says: same X โ†’ same Y across different tuples. Correct: Think of it as: "If two tuples have the same X, they MUST have the same Y."

Pitfall 2: Confusing Attribute Closure with FD Closure

The Mistake: Using Fโบ and ฮฑโบ interchangeably. Why It's Wrong:
  • F+F^+ = all FDs derivable from F (a set of FDs)
  • ฮฑ+\alpha^+ = all attributes derivable from ฮฑ (a set of attributes) Memory Aid: F+F^+ has a superscript + on the FD set; ฮฑ+\alpha^+ has it on the attribute set.

Pitfall 3: Assuming Transitivity Works Backwards

The Mistake: "A โ†’ B and A โ†’ C implies B โ†’ C." Why It's Wrong: Transitivity requires a chain: X โ†’ Y and Y โ†’ Z gives X โ†’ Z. A โ†’ B and A โ†’ C mean both B and C are determined by A, but there's no relationship between B and C. Correct: From A โ†’ B and A โ†’ C, we can use UNION to get A โ†’ BC, then DECOMPOSITION to get back to A โ†’ B and A โ†’ C. But we cannot derive B โ†’ C.

๐Ÿ“ Practice Questions

Q1. What is a functional dependency? Give a real-world example.

Answer
A functional dependency Xโ†’YX \rightarrow Y means: if two tuples have the same value for attribute(s) X, they must have the same value for attribute(s) Y.
Real-world example: In a student table, studentidโ†’studentnamestudent_id \rightarrow student_name โ€” any two rows with the same student_id must have the same student_name.

Q2. List Armstrong's three basic axioms.

Answer
  1. Reflexivity: If YโІXY \subseteq X, then Xโ†’YX \rightarrow Y
  2. Augmentation: If Xโ†’YX \rightarrow Y, then XZโ†’YZXZ \rightarrow YZ
  3. Transitivity: If Xโ†’YX \rightarrow Y and Yโ†’ZY \rightarrow Z, then Xโ†’ZX \rightarrow Z
These are sound and complete โ€” every implied FD can be derived using these rules.

Q3. Given F={Aโ†’B,Bโ†’C}F = \{A \rightarrow B, B \rightarrow C\}, compute {A}+\{A\}^+.

Answer
  1. result = {A}
  2. Aโ†’BA \rightarrow B: A โІ result โ†’ result = {A, B}
  3. Bโ†’CB \rightarrow C: B โІ result โ†’ result = {A, B, C}
  4. No more changes. {A}+={A,B,C}\{A\}^+ = \{A, B, C\}

Q4. Given R(A,B,C,D)R(A, B, C, D) and F={Aโ†’B,Aโ†’C,Bโ†’D}F = \{A \rightarrow B, A \rightarrow C, B \rightarrow D\}, find all candidate keys.

Answer
Step 1: Attributes not on RHS of any FD: A (appears only on LHS of FDs). So A is mandatory.
Step 2: Compute {A}+\{A\}^+:
  • result = {A}
  • Aโ†’BA \rightarrow B โ†’ {A, B}
  • Aโ†’CA \rightarrow C โ†’ {A, B, C}
  • Bโ†’DB \rightarrow D โ†’ {A, B, C, D} = R
Step 3: {A}+\{A\}^+ covers all attributes. Since A is a single attribute, it's minimal.
Candidate key: {A}

Q5. Check if F1={Aโ†’B,Aโ†’C}F_1 = \{A \rightarrow B, A \rightarrow C\} and F2={Aโ†’BC}F_2 = \{A \rightarrow BC\} are equivalent.

Answer
Check each FD from F1F_1 against F2F_2:
  • Aโ†’BA \rightarrow B: Using F2F_2, compute A+A^+ = {A, B, C}. B โІ A+A^+ โœ“
  • Aโ†’CA \rightarrow C: Using F2F_2, compute A+A^+ = {A, B, C}. C โІ A+A^+ โœ“
Check each FD from F2F_2 against F1F_1:
  • Aโ†’BCA \rightarrow BC: Using F1F_1, compute A+A^+ = {A, B, C}. BC โІ A+A^+ โœ“
All FDs hold in the other set. Therefore, F1F_1 and F2F_2 are equivalent.

Q6. Does ABโ†’CAB \rightarrow C hold in F={Aโ†’B,Bโ†’C}F = \{A \rightarrow B, B \rightarrow C\}?

Answer
Compute {A,B}+\{A, B\}^+:
  • result = {A, B}
  • Aโ†’BA \rightarrow B: A โІ result (B already there)
  • Bโ†’CB \rightarrow C: B โІ result โ†’ result = {A, B, C}
  • {A,B}+={A,B,C}\{A, B\}^+ = \{A, B, C\}
C โІ {A,B}+\{A, B\}^+? Yes! So ABโ†’CAB \rightarrow C holds in F.
(Note: This is expected because Aโ†’BA \rightarrow B and Bโ†’CB \rightarrow C gives Aโ†’CA \rightarrow C by transitivity, so with A alone we can determine C.)

Q7. What is a trivial FD? Give three examples.

Answer
A trivial FD Xโ†’YX \rightarrow Y is one where YโІXY \subseteq X โ€” the RHS is a subset of the LHS. Trivial FDs are always true.
Examples:
  1. Aโ†’AA \rightarrow A
  2. ABโ†’AAB \rightarrow A
  3. ABCโ†’ABABC \rightarrow AB
Non-trivial example: IDโ†’nameID \rightarrow name (name is not a subset of ID)

Q8. Given R(A,B,C,D,E)R(A, B, C, D, E) with F={Aโ†’B,BCโ†’D,Dโ†’E}F = \{A \rightarrow B, BC \rightarrow D, D \rightarrow E\}, find all candidate keys.

Answer
Step 1: Attributes not on RHS: A, C. (A appears on LHS only; C appears on LHS only; B appears on RHS of Aโ†’B; D appears on RHS of BCโ†’D; E appears on RHS of Dโ†’E)
So A and C must be in every candidate key.
Step 2: Compute {A,C}+\{A, C\}^+:
  • result = {A, C}
  • Aโ†’BA \rightarrow B โ†’ {A, B, C}
  • BCโ†’DBC \rightarrow D โ†’ {A, B, C, D}
  • Dโ†’ED \rightarrow E โ†’ {A, B, C, D, E} = R
Step 3: {A,C}+\{A, C\}^+ = R. Is it minimal?
  • Remove A: {C}+={C}โ‰ R\{C\}^+ = \{C\} \neq R
  • Remove C: {A}+={A,B}โ‰ R\{A\}^+ = \{A, B\} \neq R (no BC โ†’ D without C)
Candidate key: {A, C}

๐Ÿ”— Cross-References

Document outline

Keep your place and jump directly to a heading.

Table of contents

No note selected

Open a chapter to see its outline, backlinks, and sources here.