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 second normal form.
For a table to be in second normal form, it needs to satisfy the following conditions:
Partial dependency is when a non-prime attribute is dependent on any proper subset of any candidate key of the table.
Now, let’s look at a concrete example of a table that is currently not in second normal form:
Person_ID | Source | Destination |
---|---|---|
1 | Lahore | Karachi |
1 | Multan | Islamabad |
2 | Quetta | Peshawar |
3 | Lahore | Karachi |
4 | Multan | Islamabad |
In the example, the table has a composite primary key [Person_ID, Source] while Destination is the non-key attribute. However, since Destination is only dependent on Source, which is only part of the primary key, a partial dependency arises. Therefore, this table does not satisfy the second normal form.
We can decompose it to 2NF by removing this partial dependency. To do so, let’s break the table into two like this:
ID | Source |
---|---|
1 | Lahore |
1 | Multan |
2 | Quetta |
3 | Lahore |
4 | Multan |
Source | Destination |
---|---|
Lahore | Karachi |
Multan | Islamabad |
Quetta | Peshawar |