✏️ Explanatory Question

What is database normalization and what are the normal forms?

👁 10 Views
📘 Detailed Answer
🟢 Easy
💡

Answer with Explanation

Section 10: Architecture, Security & Scaling

75

What is database normalization and what are the normal forms?

Level: Expert — A foundational design topic; interviewers expect you to explain 1NF through BCNF clearly.

Normalization is the process of organizing data in a database to reduce redundancy and eliminate anomalies (insertion, update, and deletion anomalies). It splits large tables into smaller, related tables connected by keys.

Goal: Each piece of data should be stored once, in the right place. This keeps data consistent and makes updates safe — change a value in one spot rather than dozens.

The Normal Forms (Progressive Rules)

  • 1NF (First Normal Form): Atomic values only — no repeating groups or multi-valued columns. Each cell holds a single value.
  • 2NF (Second Normal Form): Must be in 1NF + no partial dependency — every non-key column depends on the whole primary key (matters for composite keys).
  • 3NF (Third Normal Form): Must be in 2NF + no transitive dependency — non-key columns depend only on the key, not on other non-key columns.
  • BCNF (Boyce-Codd NF): A stricter 3NF — for every functional dependency, the left side must be a super key.

Normal Forms Summary

Form Rule Removes
1NF Atomic values, no repeating groups Multi-valued columns
2NF 1NF + no partial dependency Partial key dependency
3NF 2NF + no transitive dependency Non-key → non-key dependency
BCNF Every determinant is a super key Remaining key anomalies

Quick Example — Progression

-- UNNORMALIZED: repeating group of phone numbers
-- students(id, name, phone1, phone2)  -- BAD

-- 1NF: atomic values, one phone per row
CREATE TABLE student_phones (
    student_id INT,
    phone      VARCHAR(15),
    PRIMARY KEY (student_id, phone)
);

-- 2NF: split so non-key columns depend on the WHOLE key
-- Bad: order_items(order_id, product_id, product_name)
--   product_name depends only on product_id (partial)
CREATE TABLE products (
    product_id   INT PRIMARY KEY,
    product_name VARCHAR(100)
);
CREATE TABLE order_items (
    order_id   INT,
    product_id INT,
    quantity   INT,
    PRIMARY KEY (order_id, product_id)
);

-- 3NF: remove transitive dependency
-- Bad: employees(emp_id, dept_id, dept_name)
--   dept_name depends on dept_id (non-key), not emp_id
CREATE TABLE departments (
    dept_id   INT PRIMARY KEY,
    dept_name VARCHAR(50)
);
CREATE TABLE employees (
    emp_id  INT PRIMARY KEY,
    dept_id INT,
    FOREIGN KEY (dept_id) REFERENCES departments(dept_id)
);
Interviewer tip: The one-liner they want — "Normalization reduces redundancy by splitting tables. 1NF removes repeating groups, 2NF removes partial dependencies, 3NF removes transitive dependencies, and BCNF ensures every determinant is a super key."