SQL · Module 07: Schema Design, Normalization & ViewsTutorial 19 of 24
All Tutorials·~1.5 hrs

7.1 Database Normalization (1NF, 2NF, 3NF) vs Denormalization

Understand why poorly designed tables suffer from Insert, Update, and Delete anomalies, master 1NF, 2NF, and 3NF in plain English, and know when senior engineers intentionally denormalize.

01 Intuition: Plain-English mental model
02 Visuals: Step-by-step diagrams
03 Practice: Clean examples & tradeoffs

1. Why Normalize? (The 3 Data Anomalies)

Imagine storing everything in one giant table orders_flat(order_id, customer_name, customer_email, product_name, product_price):

  1. Update Anomaly: Aarav changes his email → you must update 200 order rows (miss 1 row and your data contradicts itself!).
  2. Insert Anomaly: You can't add a new product to your catalog until someone actually buys it!
  3. Delete Anomaly: If Aarav cancels his only order and you delete that row, you accidentally delete Aarav's account info too!

Normalization eliminates all 3 anomalies by organizing columns so every fact is stored in exactly ONE place.


2. 1NF, 2NF & 3NF Explained in Plain English

Famous Mnemonic (Bill Kent): "Every non-key column must depend on the key (1NF), the whole key (2NF), and nothing but the key (3NF)!"

Normal FormPlain-English RuleBad Example (Violates Rule)Clean Fix
1NF (Atomic Values)No comma-separated lists in a single cell; every row has a PKskills = 'Python, SQL, DSA'Separate user_skills(user_id, skill) table (1 skill per row)
2NF (No Partial Dependency)Every non-key column depends on the entire composite PK (not just half of it)order_items(order_id, product_id, product_name) — product_name depends only on product_id!Move product_name into products(product_id, product_name)
3NF (No Transitive Dependency)Non-key columns must not depend on other non-key columnsusers(user_id, zip_code, city) — city depends on zip_code, not user_id!Move (zip_code, city) into a postal_codes lookup table
SQL
-- Clean 3NF E-Commerce Schema (Zero Redundancy, Zero Anomalies!)
CREATE TABLE customers (
    customer_id BIGINT PRIMARY KEY,
    name        VARCHAR(100) NOT NULL,
    email       VARCHAR(255) NOT NULL UNIQUE
);

CREATE TABLE products (
    product_id   BIGINT PRIMARY KEY,
    product_name VARCHAR(150) NOT NULL,
    current_price DECIMAL(10, 2) NOT NULL
);

CREATE TABLE orders (
    order_id    BIGINT PRIMARY KEY,
    customer_id BIGINT NOT NULL REFERENCES customers(customer_id),
    created_at  TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE order_items (
    order_id      BIGINT NOT NULL REFERENCES orders(order_id),
    product_id    BIGINT NOT NULL REFERENCES products(product_id),
    quantity      INT NOT NULL CHECK (quantity > 0),
    price_at_sale DECIMAL(10, 2) NOT NULL, -- Intentionally snapshotted!
    PRIMARY KEY (order_id, product_id)
);

Pro Detail: Notice price_at_sale in order_items! Even in a 3NF schema, you snapshot the historical price at checkout so that raising products.current_price next year never alters last year's invoices!


3. Normalization vs Denormalization (When to Break the Rules!)

DimensionNormalized (3NF)Denormalized (Controlled Redundancy)
Best ForOLTP (Writes, banking, orders, user profiles)OLAP (Analytics dashboards, read-heavy feeds)
Write Speed & Integrity✅ Fast, bug-free writes (update 1 row)❌ Slower, riskier writes (must sync duplicated counters)
Read SpeedRequires JOINs across tables✅ Blazing-fast reads (0 JOINs!)
Real Exampleposts + likes tablesStoring a cached like_count INT column directly on posts so Instagram doesn't COUNT(*) 1M likes on every feed load!

4. Quick Check Your Understanding

Module 7.1 Quick Quiz

Q1.A table stores tags = 'sql,python,dsa' as a comma-separated string in one column. Which Normal Form does this violate?
Q2.Why do high-traffic apps like Instagram or YouTube intentionally denormalize a like_count column onto the posts table?

Keep Exploring: Related Lessons & Tools

All Courses →