Overview
Normalization organises tables so each fact is stored once, which prevents update, insert and delete anomalies. It is driven by functional dependencies: column set determines column set when equal values always imply equal values, written .
Core concepts
| Form | Rule (informal) |
|---|---|
| 1NF | Atomic values, no repeating groups, every row identifiable |
| 2NF | 1NF and no non-key column depends on part of a composite key |
| 3NF | 2NF and no non-key column depends on another non-key column (no transitive dependency) |
| BCNF | Every determinant is a candidate key |
Rule of thumb: every non-key attribute depends on the key, the whole key, and nothing but the key.
Worked example
A flat table order_lines(order_id, product_id, product_name, customer_name, qty) repeats product_name on every line (partial dependency on product_id) and customer_name on every line of an order. Renaming a product requires updating many rows, and an order with a typo in the customer name is inconsistent. Split into:
customers(id PK, name)
products(id PK, name)
orders(id PK, customer_id FK)
order_lines(order_id FK, product_id FK, qty, PRIMARY KEY (order_id, product_id))Pitfalls and production notes
- Denormalise on purpose. Analytical stores (star schemas, wide tables, ClickHouse) duplicate data to avoid joins. Do it for measured read performance, and keep a normalised source of truth.
- Over-normalising reference data (a table per status flag) adds joins without value; use
CHECKconstraints or small lookup tables. - Store money as
numeric/decimal, not floating point. - Natural keys change; surrogate keys (
identity/serial/sequence) are stable but add a join to find the natural key.
Practice questions
- Normalise
employee(id, dept_id, dept_name, dept_location)to 3NF. - Give a table that is in 3NF but not BCNF.
- Why do data warehouses deliberately break 3NF?
References
- PostgreSQL manual, Data Definition: https://www.postgresql.org/docs/current/ddl.html
Related
relational-model · indexing-theory · safe-schema-migrations · ch-columnar-model