Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 9

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

Recommended resources

Hello! Welcome to the first lesson of our second module, "Databases and SQL Fundamentals."

In the previous module, we built a solid foundation in Python, culminating in professional practices like managing virtual environments and writing unit tests. These skills are about ensuring your code is reliable and reproducible. Now, we turn our attention to the data that your code will manage.

This lesson introduces database normalization, a fundamental concept in database design. For a Full Stack AI Developer, understanding how to structure data correctly is non-negotiable. Whether you're storing user information, logging transactions, or preparing a dataset for a machine learning model, a well-organized database prevents critical errors and ensures data integrity.

Our goal today is to explain database normalization and demonstrate how to apply its first three stages: First Normal Form (1NF), Second Normal Form (2NF), and Third Normal Form (3NF). By the end of this lesson, you will understand why a disorganized database is problematic and how to systematically organize it into a clean, efficient structure.

1. The "Why": Problems in Unnormalized Data

Before we learn the rules of normalization, it's crucial to understand the problems it's designed to solve. When data is stored haphazardly in a single, large table, you will inevitably face issues known as data anomalies. These are errors that occur during data insertion, updating, or deletion.

  • Insertion Anomaly: You can't add a new piece of information unless another, unrelated piece of information is also present. For example, you can't add a new product to the database until a customer has actually ordered it.
  • Update Anomaly: If you need to change a piece of information that is repeated in many rows, you have to update every single one of them. Missing even one leads to inconsistent data.
  • Deletion Anomaly: Deleting one piece of information unintentionally erases other, unrelated information. For example, deleting a customer's only order might also delete the customer's entire record from the database.

These anomalies make your application buggy and unreliable. Normalization is the process of structuring your database to prevent them.

Complete guide to Database Normalization in SQL

To see these anomalies in action, let's watch a section of the video "Complete guide to Database Normalization in SQL" from techTFQ. This part clearly demonstrates the practical problems that arise from a poorly designed database.

Watch the segment from 32:37 to 40:46. Pay close attention to the examples given for insertion, deletion, and update anomalies and how a normalized structure would solve each problem.


2. The "How": The First Three Normal Forms

Normalization is a step-by-step process of applying a series of rules, known as "normal forms." A database is typically considered "normalized" if it meets the criteria for the Third Normal Form (3NF).

We will follow a single, comprehensive example from the same video. We'll start with a messy, denormalized table and progressively transform it to meet 1NF, 2NF, and 3NF.

First, let's get an overview of what normalization is.

Complete guide to Database Normalization in SQL

Let's start the video from the beginning to get a formal introduction to normalization and data redundancy.

Watch from the beginning until 05:02. This section defines normalization, explains data redundancy, and outlines the different normal forms, noting that 3NF is the industry standard.

Now, let's dive into the step-by-step process.

First Normal Form (1NF)

A table is in 1NF if it meets two conditions:

  1. Atomicity: Each cell in the table must hold a single, indivisible value. No repeating groups or comma-separated lists in a single field.
  2. Unique Rows: Each row must be unique, typically identified by a primary key.

Complete guide to Database Normalization in SQL

Let's see how to apply 1NF to our example table. The presenter will take a record with multiple values in its columns and split it to ensure atomicity.

Watch from 07:27 to 12:48. Observe how multi-valued columns are broken down into separate rows, and how a combination of columns can serve as a unique identifier for now.

After applying 1NF, we have eliminated repeating groups, but the table still contains a lot of redundant information. For example, customer details and product details are repeated for every order. This is what 2NF will address.

Second Normal Form (2NF)

A table is in 2NF if:

  1. It is already in 1NF.
  2. It has no partial dependencies. This means that all non-key attributes (columns that are not part of the primary key) must be fully dependent on the entire primary key.

This rule is mainly relevant when a table has a composite primary key (a primary key made of two or more columns). If a non-key column depends on only part of the composite key, you have a partial dependency. The solution is to split the table.

Complete guide to Database Normalization in SQL

Now we'll tackle 2NF. This is the most significant step, where we'll break our single large table into multiple smaller, related tables.

Watch from 12:57 to 26:10. This is a longer section, so focus on these key concepts: Candidate Key: The column(s) that uniquely identify a row. Partial Dependency: Identifying which columns depend on the order number and which depend on the product code. Splitting Tables: How the original table is decomposed into an orders table, a products table, and a customers table. Primary & Foreign Keys: How these new tables are linked together.

By achieving 2NF, we have significantly reduced data redundancy. Customer information is now stored only once in the customers table, and product information is stored only once in the products table.

Third Normal Form (3NF)

A table is in 3NF if:

  1. It is already in 2NF.
  2. It has no transitive dependencies. A transitive dependency occurs when a non-key attribute depends on another non-key attribute, instead of depending directly on the primary key.

For example, if A is the primary key, and we have A -> B -> C, then C has a transitive dependency on A through B. The solution, once again, is to split the table.

Complete guide to Database Normalization in SQL

The final step is to achieve 3NF by removing any transitive dependencies. In our example, we'll see that the salesperson's information doesn't belong in the orders table.

Watch from 26:10 to 32:37. Notice how the sales person information is moved into its own employees table, as it depends on the order, which in turn depends on the customer, creating a transitive dependency.

Now our database is in 3NF! We have a set of small, well-defined tables, each storing a specific type of information. Redundancy is minimized, and the data anomalies we discussed earlier are prevented.


3. Visual Summary of the Normalization Process

To help solidify these concepts, here are two diagrams that summarize the journey through the normal forms.

This first image provides a clear, step-by-step example of a Student table being normalized.

Database Normalization: 1NF, 2NF, 3NF Explained
This image illustrates the transformation of a single table through 1NF, 2NF, and 3NF. It shows how repeating groups are eliminated for 1NF, partial dependencies are removed for 2NF by creating a `Subject` table, and transitive dependencies are resolved for 3NF by creating an `Exam` table.

This second image is a flowchart that shows the logical decisions made at each stage of normalization.

Database Normalization Process Flowchart (UNF to 3NF)
This flowchart diagrams the process from an unnormalized state to 3NF. It highlights the key tests at each step: removing repeating groups for 1NF, checking for partial dependencies to reach 2NF, and checking for transitive dependencies to reach 3NF.

4. Further Review (Optional)

The video we watched provided a fantastic, in-depth example. To reinforce your understanding, it can be helpful to see the same principles applied to a different scenario.

Database Normalization – Normal Forms 1nf 2nf 3nf Table Examples

The following article from freeCodeCamp offers another excellent, concise walkthrough of normalizing a database, this time using an 'employees' table. Reading through a second example is a great way to confirm your understanding.

Read the section 'Examples of 1NF, 2NF, and 3NF'. Follow how the initial employees table is progressively broken down to achieve 2NF and finally 3NF.


Conclusion

In this lesson, you've learned one of the most important principles of database design. You now understand not just how to normalize a database, but why it's so critical for building robust and reliable applications.

Key Takeaways:

  • Data Anomalies (insertion, update, deletion) are serious problems caused by poor database design.
  • Normalization is the systematic process of organizing tables to reduce data redundancy and eliminate anomalies.
  • 1NF ensures each cell has one value (atomicity) and each row is unique.
  • 2NF builds on 1NF and removes partial dependencies by splitting tables.
  • 3NF builds on 2NF and removes transitive dependencies, resulting in a clean, normalized design.
  • The core technique involves decomposing large tables into smaller, single-purpose tables linked by primary and foreign keys.

You are now equipped with the foundational theory of relational database structure. In our next lesson, we will get hands-on and start interacting with these structures by learning to write basic SQL queries to retrieve data using SELECT, WHERE, and ORDER BY.