- Published on
Database Normalization: BCNF
BCNF (Boyce-Codd Normal Form) is a type of database normalization that is stricter than 3NF (Third Normal Form). It's used to eliminate redundancy and potential anomalies in relational database design.
π TL;DR
A relation is in BCNF if every determinant is a candidate key.
π Quick Breakdown
- A determinant is any attribute (or set of attributes) on the left-hand side of a functional dependency (e.g.,
A β B, A is the determinant). - A candidate key is a minimal set of attributes that can uniquely identify every tuple (row) in the relation.
π Formal Definition
A relation R is in Boyce-Codd Normal Form (BCNF) if:
For every non-trivial functional dependency
X β YinR,Xis a super key (i.e., it can uniquely identify tuples).
"Non-trivial" means Y is not a subset of X.
β When Is BCNF Needed?
Even if a table is in 3NF, it might still not be in BCNF if:
- There are multiple candidate keys, and
- Some non-primary candidate key determines attributes
π§ Example
Letβs say you have a table:
| StudentID | Course | Instructor |
|---|---|---|
| 1 | Math | Prof. A |
| 2 | Math | Prof. A |
| 3 | History | Prof. B |
Functional dependencies:
StudentID β Course, Instructorβ (StudentID is a candidate key)Course β Instructorβ (Course is not a candidate key)
Here, Course β Instructor violates BCNF because Course is not a superkey.
π‘ Fixing It
Split into two tables:
- StudentCourse(StudentID, Course)
- CourseInstructor(Course, Instructor)
Now both are in BCNF, and the redundancy is removed.
Here are the BCNF-fixed tables derived from the example:
1) StudentCourse
Stores which course each student takes. PK: (StudentID, Course)
| StudentID | Course |
|---|---|
| 1 | Math |
| 2 | Math |
| 3 | History |
2) CourseInstructor
Captures the functional dependency Course β Instructor. PK: Course
| Course | Instructor |
|---|---|
| Math | Prof. A |
| History | Prof. B |