Learn SQL
-- fundamentals.normalization_1nf_3nf

Normalization: 1NF → 2NF → 3NF in SQL

Atomic cells, whole-key dependence, no transitive lies

--concept

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.

--how it works
1

1NF atomizes

One value per cell. Split comma-lists into rows; no repeating column groups.

2

2NF needs whole keys

With composite keys, every non-key column must need the full key — not half of it.

3

3NF removes transitives

Non-keys depend only on the key. City lives in customers, orders reference it.

4

Denormalize deliberately

Proven hotspots only: counters, rollups, star dims — single writer + reconcile job + comment.

--visualization
1NF: atomic2NF: whole-key3NF: key-only
Stage 1 / 1
3NF: city lives once in customers; orders join.
--example
query.sql
1-- 3NF: city lives once
2CREATE TABLE customers (id INT PRIMARY KEY, city TEXT);
3CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT REFERENCES customers(id));
Result
formrule
1NFatomic cells
2NFwhole-key dependence
3NFno 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.

--variants

Comma-list to rows (1NF)

Atomic cells enable joins and counts.

query.sql
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;
Result
order_idlines
1013
1021
1CSV cannot join, count, or constrain per item.
2Rows join to products and tally per order.
31NF is the join-enabler.

City moves to customers (3NF)

One update fixes a move; no disagreeing copies.

query.sql
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;
Result
order_idcity
101Berlin
102Madrid
1City stored once per customer.
2Orders resolve via FK join.
3Move updates one row, not ten order copies.
--key facts
1NFatomic cells, no repeating groups
2NF/3NFwhole key, then key-only dependence
Denormalizeproven hotspots + single-writer + reconcile
--use cases
Greenfield OLTP: 3NF default before proving hotspots
Anomaly triage: disagreeing copies, partial-key bugs
--under the hood
Normalized writes touch narrow rows — hot updates stay cache-friendly; wide denormalized rows rewrite more.
Denormalized marts are fed by batch ETL — freshness lag is the contracted cost.

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Take the queries you just visualized and see the data structures that power real databases.