The process of normalization refers to the reduction of redundancy from a set of relations. In database tables, we can use normal forms to carry out this process. 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 Boyce-Codd normal form.
For a relation to be in BCNF, it needs to satisfy the following conditions:
| A | B | C |
|---|---|---|
| A1 | B1 | C1 |
| A1 | B2 | C2 |
| A2 | B1 | C1 |
| A3 | B3 | C3 |
In the above relation, AB is the key. However, there is a functional dependency, as follows:
The relation is in the first three normal forms because:
However, the table is not in BCNF because in the dependency given above, C is not a superkey.
To achieve BCNF, we will have to remove the given dependency by splitting the table into two, as follows:
| A | B |
|---|---|
| A1 | B1 |
| A1 | B2 |
| A2 | B1 |
| A3 | B3 |
| C | B |
|---|---|
| C1 | B1 |
| C2 | B2 |
| C3 | B3 |
The first table has AB as the key. The second table has C as the key. There are no dependencies X->A where X is not a superkey. Hence, the relation is now in BCNF.
An algorithm to convert any relation to BCNF is given below.