Skip to main content
Create your own
Lesson illustration

Database Normalization: 1NF, 2NF, and 3NF

Hello! Welcome to the second module of our course, "Database Schema Design & Migrations."

In the last lesson, you wrapped up the fundamentals of Laravel by learning how to implement custom exception handling. This skill is vital for creating robust applications that can gracefully manage application-specific errors.

Now, we shift our focus from application logic to the very foundation of most applications: the database. Poor database design can lead to bugs, data inconsistencies, and significant performance problems—all things you want to avoid as you work towards mastery.

This lesson covers the first, crucial step in database design: Explain the principles of database normalization (1NF, 2NF, 3NF). This is a theoretical lesson, but it provides the essential "why" behind the database structures we will build throughout the rest of the course. Understanding these principles is fundamental to designing schemas that are not only correct but also scalable and maintainable.

1. What is Normalization and Why Is It Important?

At its core, database normalization is the process of organizing the columns and tables of a relational database to minimize data redundancy and improve data integrity. When a database is not normalized, it can suffer from "anomalies"—unintended side effects when you try to insert, update, or delete data.

For a fantastic introduction to why normalization is so critical, let's start with a video. It clearly explains the problems that normalization solves and uses a great analogy to introduce the different "normal forms" as levels of safety guarantees for your data.

Learn Database Normalization - 1NF, 2NF, 3NF, 4NF, 5NF

Watch this introductory segment from the 'Learn Database Normalization' video by Decomplexify. It lays the groundwork by explaining what data integrity is and why a normalized design is crucial for preventing logical impossibilities in your data.

Watch from the beginning until 03:55. Pay close attention to the example of a customer with two dates of birth and the analogy of 'Safety Levels' for a bridge, which maps directly to the normal forms we'll be discussing.

As the video explains, an unnormalized database can lead to:

  • Insertion Anomalies: You can't add a new piece of data because another piece of data is missing.
  • Update Anomalies: You update a piece of data, but because it's duplicated, you miss updating it in all places, leading to inconsistencies.
  • Deletion Anomalies: Deleting one piece of data unintentionally causes you to lose other, unrelated data.

The process of normalization involves applying a series of rules, or "Normal Forms," to your database design to eliminate these issues. We will focus on the first three, which cover the vast majority of real-world scenarios.

2. The First Three Normal Forms (1NF, 2NF, 3NF)

Let's break down each normal form. For a table to be in a higher normal form (like 2NF), it must first meet all the criteria of the lower forms (1NF).

Database Normalization: 1NF, 2NF, 3NF Explained
This diagram illustrates the process of taking an unnormalized table and progressively applying the rules of 1NF, 2NF, and 3NF to create a well-structured set of tables.

First Normal Form (1NF): Atomicity and No Repeating Groups

A table is in 1NF if it satisfies these four conditions:

  1. It has a primary key that uniquely identifies each row.
  2. Values in each column are atomic (indivisible). A column shouldn't contain multiple values, like a comma-separated list of tags.
  3. There are no repeating groups. This is when you have columns like project1_id, project2_id, etc. This data should be in a separate table.
  4. The order of rows does not convey information.

The next segment of the video provides clear examples for each of these violations and how to fix them.

Learn Database Normalization - 1NF, 2NF, 3NF, 4NF, 5NF

Continuing with the same video, this section details the rules of 1NF.

Watch from 03:55 to 10:25. Focus on understanding the concept of 'repeating groups' using the player inventory example. This is one of the most common 1NF violations you'll encounter.

Second Normal Form (2NF): No Partial Dependencies

A table is in 2NF if:

  1. It is already in 1NF.
  2. All non-key attributes are fully functionally dependent on the entire primary key.

This rule is mainly relevant for tables that use a composite primary key (a primary key made up of two or more columns). It means that no column should depend on only part of the composite key.

This next video segment explains this concept well, along with the update, deletion, and insertion anomalies that a 2NF violation can cause.

Learn Database Normalization - 1NF, 2NF, 3NF, 4NF, 5NF

This part of the video explains 2NF using a clear example of a composite primary key and a 'part-key dependency'.

Watch from 10:25 to 16:06. Notice how adding the Player_Rating column violates 2NF because the rating depends only on the Player, not on the combination of Player and Item_Type (the composite key). The solution is to split the data into two tables.

Third Normal Form (3NF): No Transitive Dependencies

A table is in 3NF if:

  1. It is already in 2NF.
  2. There are no transitive dependencies. This means that no non-key attribute depends on another non-key attribute.

A transitive dependency is like a chain reaction: Primary Key -> Non-Key Attribute A -> Non-Key Attribute B. Here, Attribute B's dependency on the primary key is indirect (or "transitive").

A helpful mnemonic for 3NF is that every non-key attribute "must depend on the key, the whole key, and nothing but the key."

  • "The key" (covered by 1NF)
  • "The whole key" (covered by 2NF)
  • "And nothing but the key" (covered by 3NF)

Let's see the final video segment on this topic.

Learn Database Normalization - 1NF, 2NF, 3NF, 4NF, 5NF

This final segment explains 3NF and the concept of transitive dependencies.

Watch from 16:06 to 20:13. The example of Player_Skill_Level determining Player_Rating is a perfect illustration of a transitive dependency. The fix, once again, is to split the data into separate, related tables.

3. A Practical Example in MSSQL

Now that we've covered the theory, let's see how it applies in practice with SQL. The following article walks through normalizing a poorly designed Customers table, providing MSSQL code snippets to fix violations of 1NF, 2NF, and 3NF. This should resonate with your goal of focusing on MSSQL.

Database Normalization in SQL with Examples

This article from SQLServerCentral, titled 'Database Normalization in SQL with Examples', provides a step-by-step walkthrough of normalizing a table to 3NF using SQL commands.

Read from the 'Example' section to the end. Follow how the initial Customers table is refactored to satisfy each normal form: For 1NF: See how they add a primary key, split the ContactPersonAndRole column (atomicity), and move the repeating Project columns into a new ProjectFeedback table. For 2NF: Observe how they move columns that depend on the ContactPerson (not the Customer) into a new ContactPersons table. For 3NF: Pay close attention to the classic Zip and City example, where they remove the transitive dependency by creating a ZipCodes table.

Here's a concise visual summary of the rules we've just discussed:

Database Normalization: 1NF, 2NF, and 3NF Overview
This image provides a clear, at-a-glance summary of the primary rules for First, Second, and Third Normal Form.

4. Normalization and Performance

Your goal includes query optimization. It's important to understand that normalization and performance have a complex relationship.

  • Benefit: A normalized database is typically smaller and more consistent, which can lead to more efficient updates, inserts, and deletes.
  • Drawback: Retrieving data from a highly normalized database often requires joining multiple tables. These JOIN operations can be computationally expensive and may slow down complex SELECT queries.

Because of this, developers sometimes intentionally violate normalization rules—a process called denormalization—to improve read performance. For example, you might add a redundant product_name column to an orders table to avoid joining with the products table every time you list orders.

This is a trade-off: you sacrifice some data integrity and increase redundancy for faster reads. Making this decision wisely is a key skill for experienced developers.

The Biggest Database Design Mistake

This short clip from Boot.dev offers a pragmatic take for software engineers on when and why you might consider denormalization.

Watch from 07:54 to 08:39. The key message is to aim for full normalization (3NF/BCNF) by default and only denormalize when you have a specific, proven performance reason to do so.

Conclusion

In this lesson, we've laid the theoretical groundwork for solid database design. Understanding these principles is not just an academic exercise; it directly impacts the quality, maintainability, and performance of the applications you build.

Key Takeaways:

  • Normalization is the process of structuring a database to reduce data redundancy and prevent insertion, update, and deletion anomalies.
  • First Normal Form (1NF): Ensures every row has a unique primary key, all values are atomic (indivisible), and there are no repeating groups.
  • Second Normal Form (2NF): Requires 1NF and that all non-key columns depend on the entire primary key (no partial dependencies).
  • Third Normal Form (3NF): Requires 2NF and that no non-key column depends on another non-key column (no transitive dependencies).
  • The Golden Rule: "Every non-key attribute must depend on the key, the whole key, and nothing but the key."
  • Denormalization is the intentional violation of these rules, trading data integrity for improved read performance, and should be used judiciously.

Next Up:

You've learned the principles. In the next lesson, we will put them into practice. You will be tasked to design a normalized database schema for a given application specification, applying your knowledge of 1NF, 2NF, and 3NF to a real-world problem.

Can't find a good explanation? Sign up and we'll make it for you

Sign up