16 - Normalization: 1NF, 2NF, 3NF
2392 words
12 min read
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
# 16 - Normalization: 1NF, 2NF, 3NF ## 🎯 Learning Objectives After reading this topic, you will be able to: - Identify insertion, deletion, and update anomalies - Define and apply 1NF, 2NF, and 3NF - Distinguish between prime and non-prime attributes - Detect partial dependencies and transitive dependencies - Norma...

16 - Normalization: 1NF, 2NF, 3NF
🎯 Learning Objectives
After reading this topic, you will be able to:
- Identify insertion, deletion, and update anomalies
- Define and apply 1NF, 2NF, and 3NF
- Distinguish between prime and non-prime attributes
- Detect partial dependencies and transitive dependencies
- Normalize a relation up to 3NF
📋 Prerequisites
- 14 - Functional Dependencies — FDs, attribute closure, candidate keys
- 15 - Canonical Cover — Minimal FD set
📖 Core Content
16.1 Intuition: Why Normalize?
Imagine tracking employee projects in a single table:
| emp_id | emp_name | dept | project | project_budget |
|---|---|---|---|---|
| 101 | Alice | CS | Alpha | 50000 |
| 101 | Alice | CS | Beta | 30000 |
| 102 | Bob | Math | Gamma | 20000 |
Problems:
- Update anomaly: If Alice changes departments, we must update EVERY row with emp_id=101
- Insertion anomaly: Can't add a new department without assigning an employee
- Deletion anomaly: If Bob leaves, we lose info about Project Gamma Normalization is the process of decomposing tables to eliminate these anomalies. It's a series of tests (normal forms) that a schema can pass or fail.
Why This Matters: Normalization is the core of good database design (~13% of exam questions). A non-normalized database leads to data inconsistencies and maintenance nightmares.
16.2 Anomalies in Detail
| Anomaly | Definition | Example |
|---|---|---|
| Insertion | Can't insert data without additional unrelated data | Can't add a department without an employee |
| Deletion | Deleting data removes unintended information | Deleting Bob deletes Project Gamma info |
| Update | Changing data requires multiple row updates | Changing Alice's department requires 2 updates |
16.3 The Normal Forms Hierarchy
(Diagram)
Each normal form is a superset of the previous one:
16.4 Key Terminology
Before understanding normal forms, master these terms:
| Term | Definition | Example |
|---|---|---|
| Prime attribute | An attribute that is part of ANY candidate key | In R(A,B,C) with CK {A,B}, A and B are prime |
| Non-prime attribute | An attribute NOT part of any candidate key | C is non-prime |
| Partial dependency | A non-prime attribute depends on part of a candidate key | In R(A,B,C) with CK {A,B}, A→C would be partial |
| Transitive dependency | A non-prime attribute depends on another non-prime attribute | A → B and B → C means C is transitively dependent on A |
16.5 First Normal Form (1NF)
Definition: A relation is in 1NF if every attribute has atomic (indivisible) values.
Violation: A table with a column containing multiple values (like a list).
Bad (not 1NF):
| id | name | phones |
|---|---|---|
| 1 | Alice | 555-1234, 555-5678 |
Good (1NF):
| id | name | phone |
|---|---|---|
| 1 | Alice | 555-1234 |
| 1 | Alice | 555-5678 |
Important: In DBMS theory, we assume all relations are in 1NF by default. Multi-valued attributes are not allowed in the pure relational model.
16.6 Second Normal Form (2NF)
Definition: A relation is in 2NF if:
- It is in 1NF
- No non-prime attribute is partially dependent on any candidate key Check: For every candidate key CK and every proper subset S ⊂ CK, there is no FD S → A where A is non-prime.
Worked Example: 2NF Check
R(A,B,C,D) with F={AB→C,A→D}. Candidate keys? Compute {AB}+ = {A, B, C, D} = R. {A}+ = {A, D} ≠ R. {B}+ = {B} ≠ R. So CK = {A, B}.
Check partial dependencies:
- A→D: A ⊂ CK {A, B}, and D is non-prime. This is a partial dependency!
- AB→C: LHS = full CK, not a subset. Not partial. Since A→D is a partial dependency, R is NOT in 2NF. Fix: Decompose R into:
- R1(A,D) — covers the partial dependency
- R2(A,B,C) — the remaining attributes with the original CK Now both R1 and R2 are in 2NF.
Example 2: 2NF Check
R(A,B,C,D) with F={AB→C,B→D}.
Candidate key: {A, B} (assuming A+=A, B+=B, AB+=A,B,C,D).
Check partial dependencies:
- B→D: B ⊂ CK {A, B}, D is non-prime. Partial dependency!
- R is NOT in 2NF.
16.7 Third Normal Form (3NF)
Definition: A relation is in 3NF if:
- It is in 2NF
- No non-prime attribute is transitively dependent on any candidate key OR: For every non-trivial FD X→A, either:
- X is a superkey, OR
- A is a prime attribute (part of some candidate key) Alternative definition: A relation is in 3NF if for every non-trivial FD X→A:
Worked Example: 3NF Check
R(A,B,C,D) with F={A→B,B→C}. Candidate key: {A, D} (since D doesn't appear on RHS, and {A,D}+ = {A, B, C, D}).
Check transitive dependency:
- A→B: A is not a superkey (A+ = {A,B,C} ≠ R). B is non-prime. Violation of 3NF!
- B→C: B is not a superkey (B+ = {B,C} ≠ R). C is non-prime. Violation! R is NOT in 3NF. Fix: Decompose into:
- R1(A,B,C) — covers the FDs (PK = A)
- R2(A,D) — has the original CK Now check 3NF for the decomposition:
- R1(A,B,C) with F={A→B,B→C}:
- CK = {A}.
- A→B: A is a superkey. ✓
- B→C: B is not a superkey, C is non-prime. Still violates 3NF! Need to further decompose R1:
- R11(A,B) — covers A→B
- R12(B,C) — covers B→C
Example 2: 3NF Check
R(A,B,C) with F={A→B,B→C}. CK = {A}.
Check:
- A→B: A is a superkey. ✓
- B→C: B is NOT a superkey (B+ = {B,C} ≠ R). C is non-prime. Violation! Not in 3NF. Decompose to R1(A,B) and R2(B,C).
Example 3: 3NF with Prime Attribute on RHS
R(A,B,C) with F={AB→C,C→A}. Candidate keys: {A, B} (since AB+ = {A,B,C}) and {C, B} (since {C,B}+ = {A,B,C}).
Prime attributes: A, B, C (all are prime!).
Check:
- AB→C: AB is a superkey. ✓
- C→A: C is not a superkey (C+ = {A,C} ≠ R). BUT A is a prime attribute (part of {A,B}). This is allowed in 3NF! So R IS in 3NF (but NOT in BCNF — that's the distinction we'll see later).
16.8 Normalization: Step-by-Step Process
(Diagram)
16.9 Worked Example: Complete Normalization
Given: R(A,B,C,D,E) with F={AB→C,A→D,C→E}
Step 1: Find candidate keys.
- Attributes not on RHS: A, B (both appear on LHS only)
- {A,B}+: {A,B} → AB→C → {A,B,C} → C→E → {A,B,C,E} → A→D → {A,B,C,D,E} = R
- CK = {A, B}. Prime: A, B. Non-prime: C, D, E. Step 2: Check 2NF.
- A→D: A ⊂ CK, D non-prime. Partial dependency!
- Not in 2NF. Step 3: Decompose to 2NF.
- R1(A,D) — covers A→D
- R2(A,B,C,E) — remaining Step 4: Check R2 for 2NF. CK of R2: {A, B}. FDs in R2: AB→C, C→E.
- AB→C: Full CK. Not partial. ✓
- C→E: C is not a subset of CK. Not partial. ✓ No partial dependencies. R2 is in 2NF. Step 5: Check R2 for 3NF. CK = {A, B}. Prime: A, B. Non-prime: C, E.
- AB→C: AB is a superkey. ✓
- C→E: C is NOT a superkey (C+ = {C,E} in R2). E is non-prime. Transitive dependency! Step 6: Decompose R2 to 3NF.
- R21(C,E) — covers C→E
- R22(A,B,C) — remaining Final 3NF decomposition: R1(A,D), R21(C,E), R22(A,B,C) All three relations are in 3NF (and also in 2NF and 1NF).
📐 Key Formulas / Concepts
| Normal Form | Condition | Violation Example |
|---|---|---|
| 1NF | All attributes are atomic | Multi-valued phone numbers |
| 2NF | 1NF + No partial dependency (non-prime → part of CK) | A→D where CK={A,B} |
| 3NF | 2NF + No transitive dependency (non-prime → non-prime) OR X→A where X is superkey or A is prime | C→E where C isn't a superkey and E is non-prime |
⚠️ Common Pitfalls
Pitfall 1: Checking 2NF Against Only the Primary Key
The Mistake: Only checking partial dependencies against the primary key, ignoring other candidate keys.
Why It's Wrong: 2NF concerns ALL candidate keys, not just the chosen primary key.
Fix: Find ALL candidate keys first. Check if any proper subset of any candidate key determines a non-prime attribute.
Pitfall 2: Confusing 3NF and BCNF
The Mistake: Thinking 3NF requires that every LHS is a superkey (that's BCNF).
Why It's Wrong: 3NF is weaker — it also allows FDs where the RHS is a prime attribute, even if the LHS isn't a superkey.
Memory Aid: 3NF = "Superkey or Prime attribute on RHS"
Pitfall 3: Not Identifying All Candidate Keys First
The Mistake: Jumping to normalization without finding all candidate keys.
Why It's Wrong: You can't check for partial/transitive dependencies without knowing what the candidate keys are. If you miss a candidate key, you might miss a violation.
Fix: Always compute all candidate keys using attribute closure before checking normal forms.
📝 Practice Questions
Q1. Define the three types of anomalies that normalization addresses.
Answer
- Insertion anomaly: Cannot insert a new row without providing unrelated data (e.g., can't add a new department without assigning an employee)
- Deletion anomaly: Deleting a row deletes unintended information (e.g., deleting an employee also deletes the department info)
- Update anomaly: Changing a value requires updating multiple rows (e.g., changing a department name requires updating every employee row)
Q2. What is 1NF? Give an example of a violation.
Answer1NF requires all attributes to have atomic (indivisible) values.Violation: A table where an attribute can contain multiple values:
| student_id | courses |
|---|---|
| 1 | CS101, MA101 |
Fix: Create separate rows for each course:
| student_id | course |
|---|---|
| 1 | CS101 |
| 1 | MA101 |
Q3. What is a partial dependency? When does it violate 2NF?
AnswerA partial dependency occurs when a non-prime attribute depends on only part of a candidate key (a proper subset).Violation: In R(A,B,C,D) with CK = {A, B} and FD A→D:
- D is non-prime, A is a proper subset of CK
- This is a partial dependency → R is NOT in 2NF
Fix: Decompose into R1(A,D) and R2(A,B,C).
Q4. Check if R(A,B,C) with F={A→B,B→C} is in 3NF.
AnswerCandidate key: {A}Prime attributes: A. Non-prime: B, C.Check 2NF: CK = {A} has no proper subset, so no partial dependency. ✓Check 3NF:
- A→B: A is a superkey. ✓
- B→C: B is NOT a superkey (B+ = {B,C}). C is non-prime. Violation!
R is in 2NF but NOT in 3NF. Decompose to R1(A,B) and R2(B,C).
Q5. Is R(A,B,C) with F={AB→C,C→B} in 3NF?
AnswerFind candidate keys:
- {A,B}+ = {A,B,C} = R. So {A,B} is a CK.
- {A,C}+: {A,C} → C→B → {A,B,C} = R. So {A,C} is also a CK.
Prime: A, B, C (all are prime — every attribute is in some candidate key).Check 3NF (alternative definition):
- AB→C: AB is a superkey. ✓
- C→B: C is not a superkey (C+ = {B,C} ≠ R). BUT B is a prime attribute. ✓
R IS in 3NF (but NOT in BCNF, as we'll see later).
Q6. What is the difference between prime and non-prime attributes?
Answer
- Prime attribute: An attribute that is part of ANY candidate key for the relation
- Non-prime attribute: An attribute that is NOT part of any candidate key
Example: In R(A,B,C,D) with candidate key {A, B}:
- Prime: A, B
- Non-prime: C, D
Q7. Normalize R(A,B,C,D) with F={A→B,AB→C,B→D} to 3NF.
AnswerStep 1: Find candidate keys.
- Attributes not on RHS: A (appears only on LHS)
- {A}+: {A} → A→B → {A,B} → B→D → {A,B,D} → AB→C → {A,B,C,D} = R
- CK = {A}. Prime: A. Non-prime: B, C, D.
Step 2: Check 2NF (no partial dependency since CK is single attribute). ✓Step 3: Check 3NF.
- A→B: A is a superkey. ✓
- AB→C: AB is a superkey (contains A). ✓
- B→D: B is NOT a superkey (B+ = {B,D}). D is non-prime. Transitive dependency!
Step 4: Decompose.
- R1(B,D) — covers B→D
- R2(A,B,C) — remaining (covers A→B and AB→C)
Final in 3NF: R1(B,D),R2(A,B,C)
Q8. Explain transitive dependency with an example.
AnswerA transitive dependency occurs when a non-prime attribute depends on another non-prime attribute through a chain of FDs.Example: In R(A,B,C) with F={A→B,B→C}, CK = {A}:
- A→B: fine (A is superkey)
- B→C: B → C where B is non-prime and C is non-prime
- This forms a transitive dependency: A→B→C
To break it, decompose into R1(A,B) and R2(B,C).
🔗 Cross-References
- Next Topic: 17 - BCNF & Higher Normal Forms
- Previous Topic: 15 - Canonical Cover
- Related: 18 - Decomposition (how to split relations properly)
- Related: 12 - ER Model (good ER design leads to normalized relations)
- Textbook: Silberschatz, Korth, Sudarshan — Chapter 8 (Relational Database Design) Join Discord Previous15 - Canonical CoverNext17 - BCNF & Higher Normal Forms