4.1 Why Normalization? Anomalies & Functional Dependencies
Database Normalization is the systematic process of organizing relation schemas to minimize data redundancy, avoid update anomalies, and maximize referential integrity. In an unnormalized database, duplicate data wastes disk space and creates operational vulnerabilities during routine inserts, updates, and deletes.
Figure 4.1: Functional Dependencies dictate that determinant X uniquely identifies dependent Y. Flawed schemas cause Insertion, Deletion, and Update anomalies.
Types of Functional Dependencies
- Trivial FD: If $Y subseteq X$, then $X ightarrow Y$ is trivial (e.g., ${Roll_No, Name} ightarrow Name$). It conveys no new constraints.
- Non-Trivial FD: If $Y otsubseteq X$, then $X ightarrow Y$ is non-trivial (e.g., $Roll_No ightarrow Name$).
- Full Functional Dependency: Attribute $Y$ is functionally dependent on composite attribute $X$, and cannot depend on any proper subset of $X$.
- Partial Dependency: Attribute $Y$ is dependent on a proper subset of a composite candidate key. (Violates 2NF).
- Transitive Dependency: If $X ightarrow Y$ and $Y ightarrow Z$ (where $Y$ is not a candidate key and $Z$ is non-prime), then $X ightarrow Z$ is transitive. (Violates 3NF).
Armstrong's Axioms
A sound and complete set of inference rules used to derive all functional dependencies implied by a given set $F$:
- Reflexivity: If $Y subseteq X$, then $X ightarrow Y$.
- Augmentation: If $X ightarrow Y$, then $XZ ightarrow YZ$ for any attribute set $Z$.
- Transitivity: If $X ightarrow Y$ and $Y ightarrow Z$, then $X ightarrow Z$.
- Union (Derived): If $X ightarrow Y$ and $X ightarrow Z$, then $X ightarrow YZ$.
- Decomposition (Derived): If $X ightarrow YZ$, then $X ightarrow Y$ and $X ightarrow Z$.
- Pseudo-transitivity (Derived): If $X ightarrow Y$ and $WY ightarrow Z$, then $WX ightarrow Z$.
4.2 1NF, 2NF, and 3NF: Step-by-Step Normalization
Normalization progresses in stages called Normal Forms (NFs). Each normal form enforces a stricter set of structural constraints than the preceding one, systematically stripping away partial and transitive dependencies.
Figure 4.2: Normal Forms are strictly nested: BCNF ⊂ 3NF ⊂ 2NF ⊂ 1NF. Each level eliminates a distinct class of redundancy.
1NF: First Normal Form
A relation is in 1NF if and only if all attribute values are atomic (indivisible). Columns containing comma-separated lists, JSON blobs, or repeating groups violate 1NF.
-- VIOLATION of 1NF:
-- Student(ID: 101, Name: "Aman", Phones: "9876543210, 9123456789")
-- RESOLUTION into 1NF:
-- Split multi-valued attribute into separate rows or a dedicated child table:
-- Student_Phones(StudentID, Phone) -> (101, "9876543210"), (101, "9123456789")
2NF: Second Normal Form
A relation is in 2NF if it is in 1NF and no non-prime attribute is partially dependent on any candidate key. Note: If a table's candidate key contains only a single column, it is automatically in 2NF!
-- Given Enrollments(StudentID, CourseID, CourseFee, Grade)
-- Composite Candidate Key: {StudentID, CourseID}
-- Partial Dependency: CourseID -> CourseFee (CourseFee depends only on part of the PK!)
-- RESOLUTION into 2NF: Decompose into two tables:
-- 1. Enrollments(StudentID, CourseID, Grade) -> PK: {StudentID, CourseID}
-- 2. Courses(CourseID, CourseFee) -> PK: CourseID
3NF: Third Normal Form
A relation is in 3NF if it is in 2NF and no non-prime attribute is transitively dependent on the primary key. Formally, for every non-trivial functional dependency $X ightarrow A$:
- Either $X$ is a Super Key, OR
- $A$ is a Prime Attribute (member of some candidate key).
4.3 Boyce-Codd Normal Form (BCNF) & Higher Normal Forms
Boyce-Codd Normal Form (BCNF) is a stricter version of 3NF (often referred to as 3.5NF). It eliminates the "prime attribute exception" permitted by 3NF.
Formal BCNF Definition:
A relation $R$ is in BCNF if and only if for every non-trivial functional dependency $X ightarrow Y$, the determinant $X$ is strictly a Super Key.
The Classic 3NF vs BCNF Dilemma
Consider a relation Student_Counselor(StudentID, Subject, Advisor) with constraints:
- A student has one advisor per subject:
{StudentID, Subject} → Advisor - Each advisor teaches only one subject:
Advisor → Subject - Candidate Keys:
{StudentID, Subject}and{StudentID, Advisor}
Check Advisor → Subject: Advisor is NOT a super key, but Subject is a prime attribute (part of {StudentID, Subject}). Therefore, this table is in 3NF, but violates BCNF!
Lossless Join vs Dependency Preservation
| Normal Form | Lossless Join Guaranteed? | Dependency Preservation Guaranteed? |
|---|---|---|
| 3NF | YES | YES |
| BCNF | YES | NO (May be lost!) |
4NF and 5NF Overview
- 4NF (Fourth Normal Form): Deals with Multi-valued Dependencies ($X woheadrightarrow Y$). Enforces that for every non-trivial MVD, $X$ is a superkey.
- 5NF (Project-Join Normal Form / PJNF): Eliminates Join Dependencies, where a table cannot be losslessly reconstructed from smaller projections without including all original columns.