Post

SQL Normalization: 1NF 2NF 3NF BCNF with Examples

Learn SQL normalization from scratch. Covers 1NF, 2NF, 3NF, and BCNF with step-by-step table examples, anomaly fixes, and when to denormalize.

SQL Normalization: 1NF 2NF 3NF BCNF with Examples

🗃️ Database Normalization — Layman’s Guide + Interview Tips


🧠 The Core Idea (One-Line Explanation)

Normalization = Organizing your database to eliminate redundancy and ensure data makes logical sense.

Think of it like cleaning and organizing a messy closet — everything has its place, nothing is duplicated, and you can find things easily.


📦 The Analogy: Pizza Shop Orders

Imagine you store all orders in one giant table:

OrderIDCustomerNameCustomerPhonePizzaPriceChefName
1Kedar9876543210Margherita200Ravi
2Kedar9876543210Pepperoni300Ravi
3Amit1234567890BBQ250Suresh

Problems:

  • Kedar’s phone is repeated → Redundancy
  • If Kedar changes his phone, you update multiple rows → Update Anomaly
  • Delete Order 3 → Suresh disappears from DB → Deletion Anomaly
  • Can’t add a new Chef without an Order → Insertion Anomaly

Normalization fixes all of this.


📐 The Normal Forms — Simply Explained

✅ 1NF — First Normal Form: “One cell, one value”

Each column must have atomic (indivisible) values. No lists in a cell.

❌ Bad: | OrderID | Pizzas | |———|——–| | 1 | Margherita, Pepperoni |

✅ Good: Split into separate rows.

Memory trick: “1NF = No lists hiding in a cell”


✅ 2NF — Second Normal Form: “No partial dependency”

Must be in 1NF + Every non-key column must depend on the WHOLE primary key, not just part of it.

Only applies when you have a composite primary key (2+ columns as PK).

❌ Bad: (OrderID, PizzaID)ChefName depends only on OrderID, not both.

✅ Fix: Move ChefName to an Orders table.

Memory trick: “2NF = No freeloaders depending on only half the key”


✅ 3NF — Third Normal Form: “No transitive dependency”

Must be in 2NF + Non-key columns must depend only on the primary key, not on other non-key columns.

❌ Bad: OrderID → ZipCode → City (City depends on ZipCode, not OrderID directly)

✅ Fix: Move ZipCode → City to a separate Locations table.

Memory trick: “3NF = No column should depend on another non-key column”


✅ BCNF — Boyce-Codd Normal Form: “Stricter 3NF”

For every dependency A → B, A must be a super key.

Think of it as plugging edge case loopholes that 3NF misses.

Memory trick: “BCNF = 3NF with no exceptions”


✅ 4NF — “No multi-valued dependencies”

No column should have multiple independent multi-valued facts about the key.

❌ Bad: One row stores both “Skills” AND “Hobbies” for an employee (they’re unrelated to each other).

✅ Fix: Separate tables for Skills and Hobbies.


✅ 5NF — “No join dependency”

A table should not be reconstructible by joining smaller tables unless those joins are based on keys.

Rarely asked in interviews unless for senior/architect roles.


🎯 Quick Reference Cheat Sheet

Normal FormRule in Plain EnglishAnomaly Fixed
1NFOne value per cell, no repeating groupsAtomic data
2NFWhole key dependency (no partial)Partial dependency
3NFOnly key dependency (no transitive)Transitive dependency
BCNFEvery determinant is a super keyEdge cases of 3NF
4NFNo independent multi-valued factsMulti-valued dependency
5NFNo redundant join dependenciesJoin dependency

💼 Interview Tips & Tricks

🔥 Top Questions + Ideal Answers

Q: What is Normalization?

“It’s the process of organizing database tables to reduce data redundancy and improve data integrity by following a set of rules called Normal Forms.”


Q: What are anomalies? Why does normalization fix them?

Mention the 3 anomalies with examples:

  • Insert Anomaly – Can’t add data without unrelated data
  • Update Anomaly – Same data in many places, update becomes inconsistent
  • Delete Anomaly – Deleting a record accidentally removes other useful data

Q: What’s the difference between 2NF and 3NF?

  • 2NF is about partial dependency (part of composite key)
  • 3NF is about transitive dependency (non-key → non-key)

Q: When would you DE-normalize?

“In read-heavy systems (like analytics/reporting/data warehouses), denormalization improves query performance by reducing joins, at the cost of some redundancy.” — This shows practical maturity. 🌟


Q: Is BCNF always better than 3NF?

“BCNF is stricter, but achieving it can sometimes cause loss of functional dependencies, which might not always be desirable. 3NF guarantees lossless joins AND dependency preservation.”


🧩 Interview Pro Tips

TipWhy It Helps
Always mention anomalies before normalizationShows you understand the “why”
Use the phrase “functional dependency”Sounds technical and precise
Mention denormalization tradeoff for OLAPShows real-world awareness
Know 1NF–3NF deeply; BCNF is a bonusMost interviews stop at BCNF
Draw a small before/after table on whiteboardVisual aids impress interviewers

🏆 The Golden Memory Trick

“Every Normal Form fixes one more dependency problem:”

  • 1NF → Atomic ✅
  • 2NF → No Partial ✅
  • 3NF → No Transitive ✅
  • BCNF → No Exception ✅

Think of it as leveling up a video game — each level fixes a new type of mess! 🎮

This post is licensed under CC BY 4.0 by the author.