Normalization means splitting data into well-chosen tables so that no piece of information has to be written down twice. Done well, it removes duplicate copies, stops the data from disagreeing with itself, and turns many updates into a single-row change. This lesson explains the problems normalization solves, walks through First, Second and Third Normal Form with a student-enrolment example, and shows when a little denormalization is reasonable.
In this lesson you will learn
- Update, insert and delete anomalies
- Functional dependencies in plain words
- First Normal Form (1NF): atomic values
- Second Normal Form (2NF): no partial dependencies
- Third Normal Form (3NF): no transitive dependencies
- When denormalization makes sense
The Problem With One Big Table
Suppose every enrolment row also stores the department name and building:
-- Unnormalised: department details repeated on every row
CREATE TABLE enrolment_flat (
student TEXT, course TEXT, dept_code TEXT, dept_name TEXT, building TEXT
);
INSERT INTO enrolment_flat VALUES
('Nusrat', 'Data Structures', 'CSE', 'Computer Science', 'Block A'),
('Nusrat', 'Databases', 'CSE', 'Computer Science', 'Block A'),
('Tania', 'Databases', 'CSE', 'Computer Science', 'Block A'),
('Arif', 'Circuit Theory', 'EEE', 'Electrical Engineering', 'Block B');
-- Moving CSE to Block E needs three changes. Miss one and the data disagrees
UPDATE enrolment_flat SET building = 'Block E' WHERE student = 'Nusrat' AND dept_code = 'CSE';
SELECT DISTINCT dept_code, building FROM enrolment_flat ORDER BY dept_code, building;
Output
+-----------+----------+
| dept_code | building |
+-----------+----------+
| CSE | Block A |
| CSE | Block E |
| EEE | Block B |
+-----------+----------+
(3 rows)
The CSE department now appears to be in two buildings at once. This is an update anomaly: the same fact is stored three times, and one copy was not changed. A flat table like this also has two other problems:
- Insert anomaly: you cannot record a new department until a student enrols in one of its courses.
- Delete anomaly: if Arif drops his only course, the fact that EEE is in Block B disappears with him.
Functional Dependencies
A functional dependency A → B means “if you know A, you know exactly one B”. In the flat table, dept_code → dept_name, building: the code determines the name and building. Normalization is about making sure every column depends on the key of its own table, and on nothing else.
First Normal Form (1NF)
A table is in 1NF when every column holds a single, atomic value and there are no repeating groups.
| Not 1NF | 1NF |
|---|---|
Nusrat | Data Structures, Databases | Nusrat | Data Structures Nusrat | Databases |
Columns course1, course2, course3 | One row per student-course pair |
A list inside one cell cannot be searched, joined or constrained properly, so it is split into separate rows.
Second Normal Form (2NF)
A table is in 2NF when it is in 1NF and every non-key column depends on the whole primary key. This matters only when the key has several columns.
In an enrolment table with key (student_id, course_id), the column marks depends on both: a student’s marks in a particular course. But a column course_title depends only on course_id, which is a partial dependency. The fix is to move course details into their own courses table and keep only course_id in enrolments.
Third Normal Form (3NF)
A table is in 3NF when it is in 2NF and no non-key column depends on another non-key column. In courses(id, title, dept_code, dept_name, building), building depends on dept_code, which depends on id: a transitive dependency. Moving department details into a departments table removes it.
The result is the four-table design used throughout these lessons:
students (id PK, name, city, dept, cgpa)
departments (code PK, name, building)
courses (id PK, title, dept FK -> departments.code, credits)
enrollments (student_id FK, course_id FK, marks) PK = (student_id, course_id)
-- Normalised: each fact stored once, linked by keys
SELECT s.name AS student, c.title AS course, d.name AS department, d.building
FROM enrollments AS e
JOIN students AS s ON s.id = e.student_id
JOIN courses AS c ON c.id = e.course_id
JOIN departments AS d ON d.code = c.dept
WHERE d.code = 'CSE'
ORDER BY s.name, c.title;
-- One UPDATE now changes the building everywhere
UPDATE departments SET building = 'Block E' WHERE code = 'CSE';
SELECT code, building FROM departments WHERE code = 'CSE';
Output
+---------+-----------------+------------------+----------+
| student | course | department | building |
+---------+-----------------+------------------+----------+
| Mitu | Databases | Computer Science | Block A |
| Nusrat | Data Structures | Computer Science | Block A |
| Nusrat | Databases | Computer Science | Block A |
| Tania | Data Structures | Computer Science | Block A |
| Tania | Databases | Computer Science | Block A |
+---------+-----------------+------------------+----------+
(5 rows)
+------+----------+
| code | building |
+------+----------+
| CSE | Block E |
+------+----------+
(1 row)
A join rebuilds the combined view whenever it is needed, and moving CSE to a new building is a single UPDATE of one row, which cannot leave the data inconsistent.
Normal Forms at a Glance
| Form | Rule | Typical fix |
|---|---|---|
| 1NF | Atomic values, no repeating groups | One row per item |
| 2NF | No column depends on part of a composite key | Move it to the table for that part |
| 3NF | No column depends on another non-key column | Move the dependent columns to their own table |
| BCNF | Every determinant is a candidate key | A stricter 3NF, needed only in unusual cases |
When to Denormalize
Normalization favours correctness. Read-heavy systems such as reporting databases and data warehouses sometimes copy data on purpose (for example storing a customer’s name on each invoice, or keeping a precomputed total) to avoid many joins. Do this deliberately, after measuring, and keep the copies in sync with transactions or triggers. An invoice that must show the price at the time of sale is a valid reason to store a copy: it is a different fact from the current price.
Common Mistakes
- Storing comma-separated lists in one column.
- Repeating descriptive data (names, addresses) instead of referencing it by key.
- Over-normalizing tiny lookups into dozens of tables that make every query complex.
- Skipping foreign keys, which lets the separated tables drift apart.
Practice Exercises
Exercise 1. The table orders(order_id, customer_name, customer_phone, product, price) repeats customer details on every order. Split it into a better design.
Show answer
customers (customer_id PK, name, phone)
products (product_id PK, name, price)
orders (order_id PK, customer_id FK, order_date)
order_items (order_id FK, product_id FK, quantity, unit_price)
unit_price in order_items records the price at the time of sale, which may differ from the current product price.
Exercise 2. Which normal form does employees(id, name, dept_id, dept_manager) break, and why?
Show answer
3NF. dept_manager depends on dept_id, not directly on the employee’s id, so it belongs in a departments table.
Frequently Asked Questions
How far should I normalize?
For most applications, 3NF is the practical target. It removes nearly all anomalies while keeping the design understandable. Higher forms such as BCNF, 4NF and 5NF handle rarer cases.
Does normalization make queries slower?
It adds joins, but with proper keys and indexes joins are fast. Writes become simpler and safer. Denormalize only where measurement shows a real need.
Summary
- Normalization stores each fact once to prevent update, insert and delete anomalies.
- 1NF: atomic values. 2NF: whole-key dependency. 3NF: no non-key-to-non-key dependency.
- Joins reassemble the data; foreign keys keep it linked.
- Denormalize deliberately, not by accident.
Next: SQL Math Functions.
