Trusted answers to developer questions

What is the third normal form (3NF)?

Free System Design Interview Course

Many candidates are rejected or down-leveled due to poor performance in their System Design Interview. Stand out in System Design Interviews and get hired in 2024 with this popular free course.

Normal forms

Normalization is the process of reducing redundancy from a set of relations. In database tables, we can use normal forms to do this. The four main normal forms are:

As the figure below shows, these normal forms build upon one another progressively. In this shot, we will focus on the third normal form.

Third normal form (3NF)

For a table to be in third normal form, it needs to satisfy the following conditions:

  • It should be in second normal form
  • It should not have any transitive dependencies for non-prime attributes

Transitive dependencies are indirect relationships between values in the same table that cause functional dependencies.

For a table to not have any transitive dependencies, we need to ensure that no non-prime attribute determines another non-prime attribute as only prime attributes or candidate keys can determine non-prime attributes for a table in 3NF.

The following figure shows an example of a transitive dependency:

Now, let’s look at a concrete example of a table that is currently not in third normal form.

ID Country City
1 Pakistan Lahore
2 USA Seattle
3 Pakistan Lahore
4 USA Seattle
5 Iran Tehran

In the table above, ID is the prime attribute while the other two are non-prime. As you can see, an issue arises since Country is a non-prime attribute that determines State, another non-prime attribute.

The above dependency is transitive

To achieve 3NF, we must remove the above transitive dependency from the table in question. This can be done by splitting the table in two. We now have 3NF.

ID Country
1 Pakistan
2 USA
3 Pakistan
4 USA
5 Iran
Country State
Pakistan Lahore
USA Seattle
Pakistan Lahore
USA Seattle
Iran Tehran

RELATED TAGS

databases

CONTRIBUTOR

Anusheh Zohair Mustafeez
Did you find this helpful?