Database normalization is a way to split one big table into smaller, linked tables so that every fact is stored in exactly one place. The goal is consistency: if a fact lives in one place, you update it in one place. The most common rules are the first, second and third normal forms (1NF, 2NF, 3NF).
This post splits one table into three, step by step. The data is fictional: students at Northbridge University in Port Alder.
Why normalize a database?
Imagine the registrar keeps all course registrations in one table:
| student_no | student_name | department | department_head | courses |
|---|---|---|---|---|
| 1001 | Maya | Computer Programming | Prof. Costa | Databases I, Web Programming |
| 1002 | Noah | Computer Programming | Prof. Costa | Databases I |
| 1003 | Elena | Business Administration | Prof. Fernández | Accounting I, Entrepreneurship |
It looks tidy, but it causes three problems:
- Update problem: if the head of Computer Programming changes, you must change every student's row. Miss one and the data contradicts itself.
- Insert problem: you cannot add a new department that has no students yet, because the student part of the row would be empty.
- Delete problem: if you delete Elena, the only Business Administration student, you also lose who heads that department.
Normalization fixes these problems one step at a time.
What is first normal form (1NF)?
First normal form means every cell holds one value, and there are no repeating groups. The courses column holds a comma-separated list. To ask "who takes Databases I?" you would have to cut the text apart. Give each course its own row:
| student_no | student_name | department | department_head | course |
|---|---|---|---|---|
| 1001 | Maya | Computer Programming | Prof. Costa | Databases I |
| 1001 | Maya | Computer Programming | Prof. Costa | Web Programming |
| 1002 | Noah | Computer Programming | Prof. Costa | Databases I |
| 1003 | Elena | Business Administration | Prof. Fernández | Accounting I |
| 1003 | Elena | Business Administration | Prof. Fernández | Entrepreneurship |
Now you can query it, but there is more repetition. Maya's name and department appear twice. If you run UPDATE ... SET department_head = 'Prof. Kowalski' WHERE department = 'Computer Programming' on this table, PostgreSQL changes 3 rows for a single fact.
What is second normal form (2NF)?
Second normal form means: if the key has several columns, every other column must depend on the whole key, not on just a part of it.
A row of this table is identified by the pair (student_no, course). But student_name, department and department_head depend only on student_no. They have nothing to do with the course. Move the student facts into their own table:
student: student_no, student_name, department, department_head
registration: student_no, course
Maya's name is now written once.
What is third normal form (3NF)?
Third normal form means: a column that is not part of the key must not depend on another column that is not part of the key.
In the student table, department_head looks like a fact about the student. But it is really decided by the department. The chain is student, then department, then head. This is called a transitive dependency. Move the department facts into a table of their own and link the tables with a department id:
department: department_id, name, head
student: student_no, name, department_id
registration: student_no, course
Now a head change updates 1 row. A department without students can exist. Deleting Elena keeps the Business Administration row. All three problems are gone.
The tables could be created like this:
CREATE TABLE department ( department_id INTEGER PRIMARY KEY, name VARCHAR(40) NOT NULL, head VARCHAR(30) NOT NULL ); CREATE TABLE student ( student_no INTEGER PRIMARY KEY, name VARCHAR(30) NOT NULL, department_id INTEGER NOT NULL REFERENCES department(department_id) ); CREATE TABLE registration ( student_no INTEGER REFERENCES student(student_no), course VARCHAR(40), PRIMARY KEY (student_no, course) );
How the columns department_id and student_no link the tables is explained in [primary key vs foreign key](/blog/primary-key-vs-foreign-key).
How do you put the tables back together?
Use JOIN. The query below rebuilds the 1NF table from the three small ones:
SELECT s.name AS student, d.name AS department, d.head, r.course FROM registration r JOIN student s ON s.student_no = r.student_no JOIN department d ON d.department_id = s.department_id ORDER BY s.student_no, r.course;
| student | department | head | course |
|---|---|---|---|
| Maya | Computer Programming | Prof. Costa | Databases I |
| Maya | Computer Programming | Prof. Costa | Web Programming |
| Noah | Computer Programming | Prof. Costa | Databases I |
| Elena | Business Administration | Prof. Fernández | Accounting I |
| Elena | Business Administration | Prof. Fernández | Entrepreneurship |
Nothing was lost. "Prof. Costa" is stored in one cell, and the repeated view is built when you ask for it.
Summary
| Form | Rule | In this example |
|---|---|---|
| 1NF | One value per cell | Put each course on its own row |
| 2NF | Depend on the whole key | Move student facts out |
| 3NF | No indirect dependencies | Move department facts out |
Should you always normalize fully?
For most applications, 3NF is a good target. For read-heavy reporting, people sometimes keep some repetition on purpose (denormalization), because many joins can slow a query down. Do it only when you know why.
What to read next
- [Normalization](/learn/sql/normalization): take a messy table through the normal forms with exercises.
- [Primary key vs foreign key](/blog/primary-key-vs-foreign-key): how tables are linked.
- [SQL for beginners: the full course](/courses/sql)
- #sql
- #database normalization
- #database design
- #data modeling