You start a project with one table, because it is quick. Every order row holds the customer's name, phone and city, plus the list of products in one text column. A month later, a customer changes her phone number and you update it in three of her seven orders. Now the database disagrees with itself.
Normalization is the set of rules that prevents this. It sounds academic, but the core idea is simple: store each fact in exactly one place. This article takes one messy table through the first three normal forms, which is as far as most applications need to go.
The problems normalization solves
Duplicated data causes three kinds of trouble, called anomalies:
- Update anomaly. A fact stored in many rows must be changed in all of them. Miss one and the data is inconsistent.
- Insert anomaly. You cannot record one fact without another. If customers only exist inside order rows, you cannot add a customer who has not ordered yet.
- Delete anomaly. Deleting one fact destroys another. Delete a customer's only order and you lose the customer.
Each normal form removes a specific source of these problems.
The starting table
orders order_id | order_date | customer_name | customer_phone | customer_city | city_postal | products ---------+------------+---------------+----------------+---------------+-------------+-------------------------------- 1 | 2026-11-02 | Amina | 0550 11 22 33 | Oran | 31000 | Keyboard x1 (4500), Mouse x2 (1200) 2 | 2026-11-03 | Karim | 0661 44 55 66 | Setif | 19000 | Monitor x1 (32000) 3 | 2026-11-05 | Amina | 0550 11 22 33 | Oran | 31000 | Mouse x1 (1200) First normal form (1NF): one value per cell
A table is in 1NF when every column holds a single, atomic value and there are no repeating groups. Our products column breaks that rule: it holds a list, with quantities and prices packed into text. You cannot easily ask "how many mice did we sell?" or put an index on a product.
The fix is to give each product in an order its own row:
order_items order_id | product | quantity | unit_price | order_date | customer_name | customer_phone | customer_city | city_postal ---------+----------+----------+------------+------------+---------------+----------------+---------------+------------ 1 | Keyboard | 1 | 4500 | 2026-11-02 | Amina | 0550 11 22 33 | Oran | 31000 1 | Mouse | 2 | 1200 | 2026-11-02 | Amina | 0550 11 22 33 | Oran | 31000 2 | Monitor | 1 | 32000 | 2026-11-03 | Karim | 0661 44 55 66 | Setif | 19000 3 | Mouse | 1 | 1200 | 2026-11-05 | Amina | 0550 11 22 33 | Oran | 31000 Every cell now holds one value, and the key that identifies a row is (order_id, product). But the duplication got worse: Amina's phone now appears three times.
Second normal form (2NF): depend on the whole key
A table is in 2NF when it is in 1NF and every non-key column depends on the whole primary key, not just part of it. This only matters when the key has several columns.
Look at the columns:
-
quantitydepends on the order and the product together. Fine. -
order_date,customer_name,customer_phone,customer_city,city_postaldepend only onorder_id. -
unit_pricehere depends only onproduct(assuming one catalog price; more on that below).
These partial dependencies are why data repeats. Split the table so each fact lives with the key it depends on:
orders(order_id, order_date, customer_name, customer_phone, customer_city, city_postal) products(product, unit_price) order_items(order_id, product, quantity) Order details are stored once per order, product prices once per product.
Third normal form (3NF): no facts about non-key columns
A table is in 3NF when it is in 2NF and no non-key column depends on another non-key column. In other words, every column describes the key, the whole key, and nothing but the key.
The orders table still has two such chains:
-
customer_phoneandcustomer_citydescribe the customer, not the order. They depend onorder_idonly through the customer. -
city_postaldescribes the city. It depends oncustomer_city, not on the order.
These transitive dependencies are what caused the phone number problem. Move each fact to the table it describes:
CREATE TABLE cities ( id BIGINT PRIMARY KEY, name TEXT NOT NULL, postal TEXT NOT NULL ); CREATE TABLE customers ( id BIGINT PRIMARY KEY, name TEXT NOT NULL, phone TEXT, city_id BIGINT REFERENCES cities(id) ); CREATE TABLE orders ( id BIGINT PRIMARY KEY, customer_id BIGINT NOT NULL REFERENCES customers(id), order_date DATE NOT NULL ); CREATE TABLE products ( id BIGINT PRIMARY KEY, name TEXT NOT NULL, price INTEGER NOT NULL ); CREATE TABLE order_items ( order_id BIGINT REFERENCES orders(id), product_id BIGINT REFERENCES products(id), quantity INTEGER NOT NULL CHECK (quantity > 0), unit_price INTEGER NOT NULL, PRIMARY KEY (order_id, product_id) ); Now Amina's phone is stored once. Changing it is one UPDATE. You can add a customer before her first order, and deleting an order does not delete the customer.
A detail that matters: historical values
Notice that order_items keeps a unit_price even though products has a price. That is not a normalization mistake. The catalog price is "the price today"; the order item price is "the price this customer paid". They are different facts. If you only kept the catalog price, every past invoice would change when you raise a price. The same applies to a shipping address copied onto an order. Ask what fact a column records, not just whether the text looks the same.
Beyond 3NF
There are stricter forms. Boyce-Codd normal form (BCNF) tightens 3NF for some tables with overlapping candidate keys, and 4NF and 5NF deal with multi-valued and join dependencies. In everyday application design, reaching 3NF removes most of the practical problems.
When to denormalize
Normalization optimizes for correctness and easy writes. Sometimes reads matter more:
- Reporting and analytics. Data warehouses often use star schemas with wide, denormalized dimension tables, because they are read far more than written.
- Hot read paths. Storing an
order_totalon the order, or acomment_counton a post, saves a join or an aggregate on every page view. - Caches and search indexes. Copies built from the normalized data.
The rule: normalize first, then denormalize deliberately, with a clear plan to keep the copy in sync (a trigger, a transaction that updates both, or a background job).
Common mistakes
- Packing lists into one column (comma-separated tags, JSON arrays of IDs that should be rows) and then needing to query them.
- Over-normalizing simple values, such as a separate table for a status that is better as a
CHECKconstraint or enum. - Treating historical values as duplicates and "fixing" them away.
- Denormalizing early "for performance" without measuring a real slow query.
In short
- Normalization means storing each fact in one place to avoid update, insert and delete anomalies.
- 1NF: one value per cell, no lists. 2NF: no column depends on only part of a composite key. 3NF: no column depends on another non-key column.
- Keep historical values such as the price paid; they are different facts.
- Normalize by default, and denormalize on purpose where reads need it.
Watch the animated version: https://youtu.be/V8z8rYK8LrY
Originally published at abdeldjalilchougui.biz.