01 / 23

Database
Normalization

Learn how to organize database tables to eliminate redundancy, prevent update anomalies, and ensure data integrity using 1NF, 2NF, and 3NF.

SQL

What Is Normalization?

Normalization is a systematic process of organizing columns and tables in a relational database to minimize data redundancy and improve data integrity. It was first proposed by Edgar F. Codd in 1970.

Normalization breaks large, complex tables into smaller, related tables connected by foreign keys. Each level of normalization is called a normal form.

Why Normalize Your Database?

✓ Eliminate Redundancy
Store each fact exactly once, saving storage and preventing inconsistencies.
✓ Prevent Anomalies
Avoid insertion, update, and deletion anomalies that corrupt your data.
✓ Ensure Integrity
Enforce consistent, accurate data with clear relationships between tables.

The Three Anomalies

Poorly designed tables cause three types of data anomalies. Normalization is specifically designed to prevent all three.

1
Insertion Anomaly: You cannot add new data without also adding unrelated data. Example: can't add a new course without a student enrolled.
2
Update Anomaly: Changing one fact requires updating many rows. If you miss a row, the data becomes inconsistent.
3
Deletion Anomaly: Deleting a row accidentally removes unrelated data. Example: removing the last student in a course deletes the course info too.

Key Terminology

Primary Key
A column (or set of columns) that uniquely identifies each row. No duplicates allowed.
Functional Dependency
Column B depends on column A if knowing A's value determines B's value exactly.
Composite Key
A primary key made of two or more columns together. Crucial for understanding 2NF.
Transitive Dependency
Column C depends on column B, which depends on A. So C indirectly depends on A.

The Path to Normal Forms

Unnormalized (UNF) 1NF Atomic Values 2NF Full Dependency 3NF No Transitive Remove repeating groups Remove partial dependencies Remove transitive dependencies Each form builds on the previous one

First Normal Form: 1NF

A table is in 1NF if every column contains only atomic (indivisible) values and each row is uniquely identifiable. No repeating groups or arrays inside a single cell.

1
Atomic values: Each cell holds one and only one value. No comma-separated lists.
2
Unique rows: A primary key exists to distinguish every row.
3
No repeating groups: No columns like Phone1, Phone2, Phone3.

1NF Example

✕ NOT in 1NF StudentID Name Courses 101 Alice Math, Science 102 Bob English, Art, Math ✓ In 1NF StudentID Name Course 101 Alice Math 101 Alice Science 102 Bob English 102 Bob Art 102 Bob Math Each cell now holds exactly one value Composite PK: (StudentID, Course)

Second Normal Form: 2NF

A table is in 2NF if it is already in 1NF and every non-key column depends on the entire primary key, not just part of it. This rule only matters when the primary key is composite (multiple columns).

1
Must be in 1NF first: all atomic values, unique rows.
2
No partial dependencies: If PK = (A, B), no column should depend on just A or just B alone.
3
Fix: Move partially dependent columns into a separate table with their own key.

2NF Example

✕ In 1NF but NOT 2NF StudentID CourseID StudentName CourseName 101 C1 Alice Math 101 C2 Alice Science PK: (StudentID, CourseID) StudentName depends on StudentID CourseName depends on CourseID Both are partial dependencies! Split into 3 tables Students StudentID StudentName 101 Alice Courses CourseID CourseName C1 Math C2 Science Enrollments StudentID CourseID 101 C1 101 C2 All partial dependencies are removed. Each non-key column now depends on its table's full PK.

Third Normal Form: 3NF

A table is in 3NF if it is in 2NF and no non-key column depends on another non-key column. In other words: eliminate all transitive dependencies.

1
Must be in 2NF first: no partial dependencies.
2
No transitive dependencies: If PK determines A, and A determines B, then B transitively depends on PK through A. Move B out.
3
Fix: Create a new table with A as its PK and B as its column. Replace B in the original table with a foreign key to A.

3NF Example

✕ In 2NF but NOT 3NF OrderID CustID CustName CustCity 1001 C5 Alice NYC 1002 C5 Alice NYC
\( \text{OrderID} \rightarrow \text{CustID} \rightarrow \{\text{CustName, CustCity}\} \)
Transitive dependency! Orders OrderID CustID 1001 C5 1002 C5 Customers CustID CustName CustCity C5 Alice NYC FK CustName and CustCity now live in Customers table Update Alice's city in one place only

Partial vs Transitive Dependencies

Partial Dependency Transitive Dependency
Eliminated in 2NF 3NF
Requires Composite primary key Any primary key
Pattern Non-key depends on part of PK Non-key depends on another non-key
Example PK(A,B): C depends on A only PK(A): \( A \rightarrow B \rightarrow C \)
Fix Move C to table with PK = A Move C to table with PK = B

How to Normalize a Table

1
Identify the primary key: What column(s) uniquely identify each row?
2
Check for 1NF: Are all values atomic? Any repeating groups or multi-valued cells? Split them.
3
Check for 2NF: If composite PK, does every non-key column depend on the full PK? Move partial dependencies out.
4
Check for 3NF: Does any non-key column depend on another non-key column? Move transitive dependencies out.
5
Add foreign keys: Link your new tables together with FK references to maintain relationships.

Worked Example: Library Database

Consider an unnormalized table tracking library checkouts:

LibraryCheckouts MemberID | MemberName | Books | AuthorName ---------|------------|---------------|---------- 101 | Alice | SQL Basics, | Kim, Lee | | Data Design | 102 | Bob | SQL Basics | Kim

Library Example: Normalized Result

Members
MemberID (PK), MemberName
One row per member. No redundancy.
Books
BookID (PK), BookTitle, AuthorName
Each book stored once with its author.
Checkouts
MemberID (FK), BookID (FK)
Junction table linking members to books.
Members MemberID (PK) MemberName Checkouts MemberID (FK) BookID (FK) Books BookID (PK) BookTitle, AuthorName 1:M M:1 All three tables are in 3NF No redundancy, no anomalies

Common Mistakes

✕ Skipping Normal Forms
Jumping straight to 3NF without checking 1NF first. Each form must be satisfied in order.
✕ Ignoring Composite Keys
Assuming 2NF doesn't apply because you didn't realize your PK is composite (multi-column).
✕ Over-Normalizing
Splitting tables so much that every simple query requires 5+ JOINs. Balance normalization with practical performance.

Summary: Normal Forms at a Glance

1NF 2NF 3NF
Requires Atomic values, unique rows 1NF + no partial deps 2NF + no transitive deps
Eliminates Repeating groups, multi-values Partial dependencies Transitive dependencies
Key concern Cell-level atomicity Full key dependency Non-key independence
When to apply Always: first step Composite PK tables All tables
Common fix Split multi-value cells into rows Extract to new table Extract to new table + FK

Question 1 of 5

A table has a column called PhoneNumbers that stores values like "555-1234, 555-5678". Which normal form does this violate?

Question 2 of 5

A table has composite PK (StudentID, CourseID) and a column StudentName that depends only on StudentID. This is an example of a:

Question 3 of 5

An Orders table has PK OrderID and columns CustID, CustName, and CustCity. CustName and CustCity depend on CustID (not OrderID directly). What normal form is violated?

Question 4 of 5

If a table has a single-column primary key and all values are atomic, which of the following is always true?

Question 5 of 5

Which of the following best describes the goal of database normalization?