NF
Database normalization can be defined mathematically using functional dependencies (FDs), superkeys, candidate keys, and attribute closures. Each normal form imposes specific conditions on a relation to reduce redundancy and prevent anomalies.
1. Mathematical foundations
Let
Let
Functional dependency (FD)
A functional dependency
Example: If each student ID identifies exactly one student name,
Superkey and candidate key
A set of attributes
A candidate key is a minimal superkey:
A candidate key contains no unnecessary attribute.
Attribute closure
The closure
Thus:
- If
, is a superkey. - If
and no proper subset has this property, is a candidate key.
A prime attribute belongs to at least one candidate key. A non-prime attribute belongs to no candidate key.
2. First Normal Form (1NF)
A relation is in 1NF if every attribute contains a single value from its domain in each tuple, rather than a collection of values or a repeating group.
Informally, attributes are atomic.
Example of a violation:
| StudentID | PhoneNumbers |
|---|---|
| 1 | 9876, 8765 |
| 2 | 7654 |
PhoneNumbers contains multiple values in one cell.
A 1NF design could separate the numbers:
| StudentID | PhoneNumber |
|---|---|
| 1 | 9876 |
| 1 | 8765 |
| 2 | 7654 |
Mathematical note: 1NF is primarily a condition on the representation of attribute values, not on functional dependencies or candidate keys. Atomicity is relative to the chosen data model and domains.
3. Second Normal Form (2NF)
A relation is in 2NF if:
- It is in 1NF.
- No non-prime attribute is partially functionally dependent on any candidate key.
A partial dependency occurs when a proper subset of a candidate key determines a non-prime attribute.
Formally, for every candidate key
More precisely, the condition applies to dependencies implied by
Example
Consider:
Functional dependencies:
Assume the candidate key is:
StudentName depends only on StudentID, a proper subset of the candidate key.
Therefore, the relation violates 2NF.
Decompose it into:
The partial dependency is eliminated.
Important: If every candidate key consists of a single attribute, the relation automatically satisfies 2NF, provided it is in 1NF.
4. Third Normal Form (3NF)
A relation is in 3NF if, for every non-trivial functional dependency
at least one of the following holds:
is a superkey. is a prime attribute.
A dependency is non-trivial when
Equivalently:
This is the formal definition of 3NF.
Example
Consider:
Dependencies:
Assume StudentID is the candidate key.
Then:
follows by transitivity.
However, DeptID is not a superkey, and DeptName is non-prime. Therefore, the dependency
violates 3NF.
Decompose into:
Now department information is stored independently of individual students.
Why 3NF is stronger than 2NF: 2NF eliminates partial dependencies on candidate keys; 3NF also addresses problematic dependencies whose determinants are not superkeys, including transitive dependencies involving non-prime attributes.
5. Boyce–Codd Normal Form (BCNF)
A relation is in BCNF if, for every non-trivial functional dependency
the determinant
Unlike 3NF, BCNF has no exception for prime attributes.
Example
Consider:
Suppose:
- Each student taking a course has one instructor.
- Each instructor teaches exactly one course.
- A course can have multiple instructors.
Dependencies:
Candidate keys are:
and
All three attributes are prime. Therefore, the relation satisfies 3NF.
However,
violates BCNF because Instructor is not a superkey.
Decompose into:
Both resulting relations satisfy BCNF under the stated dependencies.
Key distinction: BCNF is stricter than 3NF. Every BCNF relation satisfies 3NF, but not every 3NF relation satisfies BCNF.
6. Fourth Normal Form (4NF)
BCNF deals with functional dependencies. 4NF also considers multivalued dependencies (MVDs).
An MVD
holds when, for a fixed value of
A relation is in 4NF if every non-trivial MVD
has
An MVD is trivial if
Example
Suppose a student can have multiple independent hobbies and languages.
The dependencies are:
If hobbies and languages are independent, every hobby-language combination may need to be represented. This creates redundancy.
Decompose into:
This eliminates the independent multivalued facts from being combined in one relation.
7. Fifth Normal Form (5NF)
5NF, also called Project-Join Normal Form (PJNF), addresses redundancy caused by join dependencies that cannot be explained solely by functional or multivalued dependencies.
A relation
Suppose:
represents suppliers, parts, and projects. Under certain business rules, the relation may be reconstructed exactly from:
The corresponding join dependency is:
meaning:
when the dependency holds.
If this join dependency is non-trivial and is not implied by candidate keys, the relation violates 5NF and can be decomposed into those projections.
This decomposition is valid only if the business rules guarantee that joining the projections reconstructs exactly the original relation without spurious tuples.
Normal forms at a glance
| Normal form | Main mathematical condition |
|---|---|
| 1NF | Atomic attribute values |
| 2NF | No partial dependency of a non-prime attribute on a candidate key |
| 3NF | Every non-trivial FD has a superkey determinant or a prime RHS attribute |
| BCNF | Every non-trivial FD has a superkey determinant |
| 4NF | Every non-trivial MVD has a superkey determinant |
| 5NF | Every non-trivial join dependency is implied by candidate keys |
The central idea is that normalization decomposes relations to eliminate redundancy while preserving information. A good decomposition should ideally be lossless (joining the decomposed relations recovers the original relation) and, where possible, preserve the functional dependencies.