Third Normal Form (3NF)
What is Third Normal Form (3NF)?
3NF is a set of guidelines for organizing relational database tables to reduce data redundancy and improve data integrity. Achieving 3NF means your tables are well-structured and efficient. Here's what you need to know:
The Two Main Rules for 3NF
-
The table must already be in Second Normal Form (2NF).
- This means there are no partial dependencies; every non-key attribute is fully dependent on the whole primary key.
-
There should be no transitive dependencies.
- A transitive dependency happens when a non-key column depends on another non-key column, not directly on the primary key.
Transitive Dependency Example:
If column A determines column B, and column B determines column C, then A indirectly determines C. In 3NF, we want to remove these indirect relationships unless the dependencies are on a candidate key.
Example: Breaking Down a Table into 3NF
Suppose we have a table:
R (A, B, C)
With the following dependencies:
- A → B
- B → C
The Problem
- A is our primary key.
- B is a non-key attribute, but C depends on B, creating a transitive dependency (A → B → C).
The Original Table Layout
| A | B | C |
|---|---|---|
| a | 1 | x |
| b | 1 | x |
| c | 2 | y |
| d | 2 | y |
| e | 3 | z |
| f | 3 | z |
Here, column C does not depend directly on A, but on B.
How to Fix This: Splitting the Table
Step 1: Move the transitive dependency (B → C) into a separate table.
Table 1: (Remove the transitive dependency)
| A | B |
|---|---|
| a | 1 |
| b | 1 |
| c | 2 |
| d | 2 |
| e | 3 |
| f | 3 |
Table 2: (Map B to C directly)
| B | C |
|---|---|
| 1 | x |
| 2 | y |
| 3 | z |
Now, all non-key fields only depend on the key, directly—no more transitive dependencies. Congratulations, your tables are now in 3NF!
Why Does 3NF Matter?
Working in 3NF keeps your databases:
- Efficient: Reduces repeated data (redundancy).
- Consistent: Less risk of update anomalies.
- Easy to maintain: Changes in one place, not many.
Comments
Post a Comment