Database Normalization Explained
Database Normalization Explained
Well, it is a process where rules are applied to all entities (tables) of the database,
in order to avoid failures in the project, such as data redundancy, mixing of different subjects
in the same entity, among other problems. The most well-known normal forms are the
first, second, and third normal forms. Basically, applying and respecting the rules of
with each of these normal forms, we can ensure a more consistent database,
a great possibility of success in your project.
An entity will be in 1NF if and only if all its attributes (columns) are atomic.
that is, not to contain repetitive groups or columns that have more than one value.
Ex.
In the table above, we can identify that the Phones field contains information for more than 1
customer's phone. In this case, we will have to create another table, so that we can
correctly store customer phone numbers. Below is how the tables should look after the
normalization.
Identify columns that are not functionally dependent on the primary key of the table
Remove the column from the table and create a new table with that data.
Ex.
In this example, we have a table that stores product sales data. To apply the
2NF, we need to separate the product data into an entity that contains only
product data, and in this orders table only data related to the orders. Here it is.
example below after the application of 2NF.
An entity is in 3NF if and only if it is in 2NF and all attributes (columns) are not
key, are mutually independent, that is, there is no functional dependence between them, and
All depend solely and exclusively on the primary key in an irreducible manner.
Identify the columns that are functionally dependent on the other non-key columns
Remove these columns
Ex.
Como podemos ver no exemplo acima, temos duas colunas indicando os valores do produto. A
The TotalValue column depends on another non-key column. This is an example of information.
redundant, that is, we can know the total value of the products without the need for
store it. In this case, we will remove the TotalValue column. After applying the 3NF, the table will look like
like this:
There are other normal forms, such as the fourth and fifth, however, with the application of these three
normal forms, we will already be able to guarantee a healthier database and thus prevent
possible problems in the future.
[Link]
verify
[Link]