Normalization: 1NF → 2NF → 3NF in SQL
Atomic cells, whole-key dependence, no transitive lies
Normalization removes redundancy: 1NF demands atomic values with no repeating groups; 2NF adds that every non-key column depends on the whole key (no partial dependency); 3NF adds no transitive dependencies (non-keys depend only on the key). Most production sits at 3NF; analytics denormalizes deliberately for read speed with documented sync contracts.
1NF atomizes
One value per cell. Split comma-lists into rows; no repeating column groups.
2NF needs whole keys
With composite keys, every non-key column must need the full key — not half of it.
3NF removes transitives
Non-keys depend only on the key. City lives in customers, orders reference it.
Denormalize deliberately
Proven hotspots only: counters, rollups, star dims — single writer + reconcile job + comment.
1-- 3NF: city lives once2CREATE TABLE customers (id INT PRIMARY KEY, city TEXT);3CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT REFERENCES customers(id));
| form | rule |
|---|---|
| 1NF | atomic cells |
| 2NF | whole-key dependence |
| 3NF | no transitive dependence |
Moving city to customers removes per-order duplication. One update fixes a move; before, ten order rows could disagree. Denormalized copies re-add speed later — deliberately, with sync.
Comma-list to rows (1NF)
Atomic cells enable joins and counts.
1-- before: orders(id, items_csv) — '1,2,3'2-- after: order_lines(order_id, line_no, product_id)3SELECT order_id, COUNT(*) FROM order_lines GROUP BY order_id;
| order_id | lines |
|---|---|
| 101 | 3 |
| 102 | 1 |
City moves to customers (3NF)
One update fixes a move; no disagreeing copies.
1-- 3NF: customers(id, city); orders(id, customer_id REFERENCES customers)2SELECT o.id, c.city FROM orders o JOIN customers c ON o.customer_id = c.id;
| order_id | city |
|---|---|
| 101 | Berlin |
| 102 | Madrid |
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Take the queries you just visualized and see the data structures that power real databases.