Quiz 2

17 - BCNF & Higher Normal Forms

1872 words
9 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

# 17 - BCNF & Higher Normal Forms ## 🎯 Learning Objectives After reading this topic, you will be able to: - Define BCNF and check if a relation satisfies it - Decompose a relation into BCNF - Identify multivalued dependencies (MVDs) and 4NF violations - Understand 5NF (PJNF) and join dependencies - Explain temporal...

17 - BCNF & Higher Normal Forms

🎯 Learning Objectives

After reading this topic, you will be able to:
  • Define BCNF and check if a relation satisfies it
  • Decompose a relation into BCNF
  • Identify multivalued dependencies (MVDs) and 4NF violations
  • Understand 5NF (PJNF) and join dependencies
  • Explain temporal databases (valid time vs. transaction time)

📋 Prerequisites

📖 Core Content

17.1 Intuition: 3NF Isn't Good Enough

3NF still allows some redundancy. Consider:
R(A,B,C) with F={ABC,CB}R(A, B, C) \text{ with } F = \{AB \rightarrow C, C \rightarrow B\}
CKs = {A,B} and {A,C}. This is in 3NF (all attributes are prime). But if C→B and C isn't a superkey, the same B value repeats for every A associated with C — redundancy! BCNF (Boyce-Codd Normal Form) tightens the rule: every LHS must be a superkey.
Why This Matters: BCNF is the gold standard for most practical schemas. While 3NF preserves all FDs, BCNF may not — but it eliminates virtually all redundancy from FDs.

17.2 BCNF Definition

Definition: A relation R is in BCNF if for every non-trivial FD XAX \rightarrow A:
X is a superkey of RX \text{ is a superkey of } R
Comparison:
Normal FormCondition for FD XAX \rightarrow A
3NFX is a superkey OR A is prime
BCNFX is a superkey (strict!)
BCNF = remove the "or A is prime" exception from 3NF.

17.3 BCNF Decomposition Algorithm

pseudo
Input: R (relation), F (FD set)
Output: Decomposition of R into BCNF relations
1. Compute closure F⁺
2. Find an FD X → Y in F that violates BCNF (X is not a superkey)
3. Compute X⁺
4. Decompose R into:
   - R₁ = X⁺ (contains the violating FD)
   - R₂ = R - (X⁺ - X) ∪ X (remaining attributes + X)
5. Repeat on R₁ and R₂ until all relations are in BCNF

Worked Example

R(A,B,C)R(A, B, C) with F={ABC,CB}F = \{AB \rightarrow C, C \rightarrow B\} Step 1: Find violating FD.
  • CKs = {A,B} and {A,C}
  • Check CBC \rightarrow B: C⁺ = {B,C} ≠ R. C is NOT a superkey. Violation! Step 2: Compute C⁺ = {B, C} Step 3: Decompose:
  • R1=C+={B,C}R₁ = C^+ = \{B, C\} (covers CBC \rightarrow B)
  • R2=R(C+C)C={A,B,C}{B}{C}={A,C}R₂ = R - (C^+ - C) \cup C = \{A, B, C\} - \{B\} \cup \{C\} = \{A, C\} Step 4: Check BCNF for R1(B,C)R₁(B, C):
  • FDs: CBC \rightarrow B
  • CK of R₁: {C}. C is a superkey for R₁. ✓
  • R₁ is in BCNF. Step 5: Check BCNF for R2(A,C)R₂(A, C):
  • No non-trivial FDs (A and C have no FD between them)
  • CK = {A, C}. R₂ is in BCNF. Result: BCNF decomposition = R1(B,C)R₁(B, C), R2(A,C)R₂(A, C) Note: ABCAB \rightarrow C is NOT preserved (we lost the connection between A and B). BCNF guarantees lossless join but NOT dependency preservation.

17.4 Multivalued Dependencies (MVDs)

An MVD XYX \rightarrow\rightarrow Y means that knowing X determines a SET of Y values, independent of other attributes. Example: An employee can have multiple dependents AND multiple projects:
emp_iddependentproject
1AliceAlpha
1AliceBeta
1BobAlpha
1BobBeta
This isn't an FD (emp_id doesn't determine a single dependent or project). But there's an MVD: empiddependentemp_id \rightarrow\rightarrow dependent (and empidprojectemp_id \rightarrow\rightarrow project). MVD Definition: XYX \rightarrow\rightarrow Y holds if, for every pair of tuples t1t_1 and t2t_2 with t1[X]=t2[X]t_1[X] = t_2[X], there exists a tuple t3t_3 such that:
  • t3[X]=t1[X]t_3[X] = t_1[X]
  • t3[Y]=t1[Y]t_3[Y] = t_1[Y]
  • t3[RXY]=t2[RXY]t_3[R - XY] = t_2[R - XY]

17.5 Fourth Normal Form (4NF)

Definition: A relation is in 4NF if:
  1. It is in BCNF
  2. For every non-trivial MVD XYX \rightarrow\rightarrow Y, X is a superkey Worked Example: The employee-dependent-project table above:
  • emp_id is NOT a superkey (emp_id alone doesn't determine a unique row)
  • MVDs exist: empiddependentemp_id \rightarrow\rightarrow dependent, empidprojectemp_id \rightarrow\rightarrow project
  • This violates 4NF Fix: Decompose into R1(empid,dependent)R₁(emp_id, dependent) and R2(empid,project)R₂(emp_id, project).

17.6 Fifth Normal Form (5NF / PJNF)

5NF (also called Project-Join Normal Form) deals with join dependencies. A join dependency means a relation can be reconstructed by joining its projections. Definition: A relation is in 5NF if for every non-trivial join dependency, every component of the join is a superkey. Practical note: 5NF is rarely violated in practice. If you've reached 4NF, you're usually in 5NF as well.

17.7 Comparison of Normal Forms

NFConditionRedundancy RemovedFD/MVD Preserved?
1NFAtomic attributesMulti-valued attrsN/A
2NFNo partial dependencyRedundancy from partial FDsYes
3NFNo transitive dependencyRedundancy from transitive FDsYes
BCNFEvery LHS is a superkeyAll FD redundancyNot always
4NFEvery MVD has superkey LHSMVD redundancyNot always
5NFEvery JD has superkey componentsJD redundancyNot always

17.8 Temporal Databases

Temporal databases store time-varying data with associated timestamps.
Time TypeMeaningExample
Valid timeWhen the fact was true in the real world"Alice was a CS student from 2020-2024"
Transaction timeWhen the fact was stored in the database"The record was inserted at 2024-01-15 10:30:00"
BitemporalBoth valid and transaction timeComplete historical tracking
Temporal relation: Each tuple has associated time intervals.
  • Valid time allows historical queries ("Show me the department structure as of Jan 2020")
  • Transaction time supports rollback queries ("Show me what the database looked like yesterday")

📐 Key Formulas / Concepts

FormTestDecomposition
BCNFFor every FD XAX \rightarrow A , XX is a superkeySplit on violating FD: (X+)(X^+) and (RX+X)(R - X^+ \cup X)
4NFFor every MVD XYX \rightarrow\rightarrow Y , XX is a superkeySplit on violating MVD: (X,Y)(X, Y) and (X,RY)(X, R - Y)
5NFFor every JD, all components are superkeysComplex; rarely needed

⚠️ Common Pitfalls

Pitfall 1: Thinking BCNF is Always Better Than 3NF

The Mistake: Always trying to achieve BCNF at all costs. Why It's Wrong: BCNF may not preserve all FDs. Sometimes 3NF is the practical choice because it guarantees dependency preservation while BCNF doesn't. Trade-off: 3NF = All FDs preserved + some redundancy; BCNF = No FD redundancy + possible FD loss.

Pitfall 2: Confusing MVDs with FDs

The Mistake: Treating XYX \rightarrow\rightarrow Y like XYX \rightarrow Y. Why It's Wrong: FDs map X to a SINGLE Y value; MVDs map X to a SET of Y values independent of other attributes. Memory Aid: FD = "one value"; MVD = "a set of values."

Pitfall 3: Decomposing Without Checking BCNF First

The Mistake: Jumping to 4NF/5NF decomposition when the issue is really a BCNF violation. Fix: Check BCNF first, then 4NF (for MVDs), then 5NF (for JDs). Most real-world schemas only need BCNF.

📝 Practice Questions

Q1. Is R(A,B,C)R(A, B, C) with F={AB,CB}F = \{A \rightarrow B, C \rightarrow B\} in BCNF?

Answer
Candidate key: {A, C} ({A,C}+\{A,C\}^+ = {A,B,C} = R).
Check FDs:
  • ABA \rightarrow B: A is NOT a superkey (A+A^+ = {A,B} ≠ R). Violation!
  • CBC \rightarrow B: C is NOT a superkey (C+C^+ = {B,C} ≠ R). Violation!
R is NOT in BCNF (but is in 3NF — check: A→B, A is not a superkey but B? B is non-prime... Actually wait — CK = {A,C}, so prime = {A,C}, B is non-prime. 3NF requires X superkey or A prime. Neither holds. So it's NOT in 3NF either.)

Q2. Check BCNF for R(A,B,C,D)R(A, B, C, D) with F={AB,ACD}F = \{A \rightarrow B, AC \rightarrow D\}.

Answer
Candidate key: {A, C} ({A,C}+\{A,C\}^+ = {A,B,C,D} = R).
Check FDs:
  • ABA \rightarrow B: A is NOT a superkey (A+A^+ = {A,B} ≠ R). BCNF violation!
  • ACDAC \rightarrow D: {A,C} is a superkey. ✓
Decompose on ABA \rightarrow B:
  • A+A^+ = {A, B}
  • R1(A,B)R₁(A, B), R2(A,C,D)R₂(A, C, D)
Check R2R₂: CK = {A, C}. FD ACDAC \rightarrow D: AC is a superkey. ✓. R₂ is in BCNF.
BCNF decomposition: R1(A,B)R₁(A, B), R2(A,C,D)R₂(A, C, D)

Q3. What is a multivalued dependency? How does it differ from an FD?

Answer
  • FD (XYX \rightarrow Y): Each X value maps to exactly ONE Y value
  • MVD (XYX \rightarrow\rightarrow Y): Each X value maps to a SET of Y values, independent of other attributes
MVDs arise when a relation has two or more independent multi-valued attributes. Example: An employee has multiple dependents AND multiple projects — these are independent.

Q4. What is 4NF? Give an example of a 4NF violation.

Answer
A relation is in 4NF if it's in BCNF and for every non-trivial MVD XYX \rightarrow\rightarrow Y, X is a superkey.
Violation example:
emp_idskilldependent
1PythonAlice
1JavaAlice
1PythonBob
1JavaBob
MVDs: empidskill,empiddependentemp_id \rightarrow\rightarrow skill, emp_id \rightarrow\rightarrow dependent emp_id is not a superkey (many rows per emp_id).
Fix: Decompose into R1(empid,skill)R₁(emp_id, skill) and R2(empid,dependent)R₂(emp_id, dependent).

Q5. Compare 3NF and BCNF. When would you choose 3NF over BCNF?

Answer
Aspect3NFBCNF
ConditionSuperkey OR prime RHSSuperkey always
FD preservationAlwaysNot always
RedundancySome possibleMinimal
DecompositionAlways dependency-preservingMay lose FDs
Choose 3NF when you need all FDs preserved and the redundancy from the "prime RHS exception" is acceptable. Choose BCNF when eliminating all FD redundancy is critical.

Q6. What is a join dependency? How does it relate to 5NF?

Answer
A join dependency (JD) means a relation can be reconstructed by joining its projections.
A relation is in 5NF (PJNF) if for every non-trivial JD, every component of the JD is a superkey.
In practice, if a relation is in 4NF and has no composite keys, it's almost certainly in 5NF. 5NF violations usually require specific constraints involving overlapping composite keys.

Q7. Explain valid time vs. transaction time in temporal databases.

Answer
  • Valid time: When the fact was true in the real world (e.g., "Alice was employed from Jan 2020 to Dec 2023"). Useful for historical queries.
  • Transaction time: When the fact was stored in the database (e.g., "this record was inserted at 10:30 AM on Jan 15"). Useful for audit and rollback queries.
A bitemporal relation stores both — allowing questions like "Show me the database state as of yesterday that reflects the real-world state in 2020."

Q8. Decompose R(A,B,C,D)R(A, B, C, D) with F={AB,BC}F = \{A \rightarrow B, B \rightarrow C\} into BCNF.

Answer
Candidate key: {A, D} ({A,D}+\{A,D\}^+ = {A,B,C,D}).
Violation: ABA \rightarrow B (A not a superkey). Also BCB \rightarrow C (B not a superkey).
Decompose on ABA \rightarrow B:
  • A+A^+ = {A, B, C}
  • R1(A,B,C)R₁(A, B, C) with FDs: AB,BCA \rightarrow B, B \rightarrow C. CK = {A}.
Check R1R₁: BCB \rightarrow C — B is NOT a superkey for R₁ (B+B^+ = {B,C} ≠ {A,B,C}). Violation!
  • Decompose R₁ on BCB \rightarrow C: R11(B,C)R₁₁(B, C), R12(A,B)R₁₂(A, B)
Result: R11(B,C)R₁₁(B, C), R12(A,B)R₁₂(A, B), R2(A,D)R₂(A, D)
All in BCNF.

🔗 Cross-References

Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.