4 Hours

3. Normalization Theory (1NF, 2NF, 3NF)

Relational Theory

The Science of Database Structure

Normalization is the mathematical process of organizing data to minimize redundancy. Redundant data is the enemy: it wastes disk space and leads to Update Anomalies (where data is updated in one place but remains old in another).

The Three Levels of Normalization

Engineers aim for Third Normal Form (3NF). Anything less is considered a Smelly database design.

1st Normal Form (1NF)

Atomic Values. No repeating groups or arrays. Every cell must contain exactly one piece of information.

2nd Normal Form (2NF)

Full Functional Dependency. Every non-key column must depend on the WHOLE primary key. Essential for tables with composite keys.

3rd Normal Form (3NF)

No Transitive Dependencies. Columns should only depend on the Primary Key, not on other non-key columns.

Identifying Update Anomalies

Why do we normalize? Imagine a Store table where we store the store_name and store_address in every single product row.

  • Insertion Anomaly: You can't add a new store until you have at least one product.
  • Deletion Anomaly: If you delete the last product, the store's address is deleted from your system forever.
  • Update Anomaly: If the store moves, you have to update 10,000 rows. If you miss one, your data is inconsistent.

When to Denormalize?

In high-scale systems, we sometimes deliberately break 3NF for Performance. This is called Denormalization. We might duplicate a username in a Comments table so we don't have to perform a JOIN every time we show a post. Warning: Only do this if you have a specific performance reason and a plan to keep the data in sync.

Knowledge Check

Ready to test your understanding of 3. Normalization Theory (1NF, 2NF, 3NF)?

Back