Part 09 / Topic 5 of 7
Normalization
Normalization is one idea applied three times: every fact lives in exactly one place. The normal forms are checkpoints along the way. Watch one bad table get fixed — a flat order sheet:
order_id | customer_name | customer_city | products
----------+---------------+---------------+--------------------------
1 | Asha | Pune | Laptop Pro 14, SQL book
2 | Ravi | Delhi | Phone X
1NF — atomic values. products holds a list; you can't filter or join on "contains laptop" sanely. Fix: one row per order line.
order_id | customer_name | customer_city | product | quantity
----------+---------------+---------------+---------------+---------
1 | Asha | Pune | Laptop Pro 14 | 1
1 | Asha | Pune | SQL book | 2
2 | Ravi | Delhi | Phone X | 1
2NF — no partial dependencies. With key (order_id, product), the column customer_name depends on part of the key (order_id alone). It repeats per line — update anomaly waiting. Fix: split order-level facts into an orders table.
3NF — no transitive dependencies. In that orders table, customer_city depends on customer, not on the order. Our customer moves and three old orders "move" with her. Fix: city lives on customers; orders point at it.
What's left is shopdb's shape: orders → customers, order_items → orders/products. Each fact once; every update touches one row. (BCNF is 3NF with one exotic corner tightened — overlapping candidate keys; if you never meet it outside an interview, you lost nothing.)
The forms aren't bureaucracy — each one deletes a specific class of bug: unsplittable lists (1NF), facts repeated per line (2NF), facts riding on the wrong entity (3NF).
🧪 Quick quiz — answer from memory, then check.
- A table keyed
(order_id, product_id)storesproduct_name. Which form breaks? customersstorescityandcity_population. Which form breaks?
Show the answers
- 2NF — product_name depends on part of the key (product_id alone).
- 3NF — city_population depends on city, not on the customer (a transitive dependency).
Done here? The practice set for Part 9 — 4 exercises with solutions — is on the part page.