Understanding of the three paradigms

There are currently six normal forms for relational databases : first normal form (1NF), second normal form (2NF), third normal form (3NF), Bath-Kord normal form (BCNF), fourth normal form (4NF) and fifth normal form ( 5NF, also known as perfect paradigm).

Usually, we use the first normal form (1NF), the second normal form (2NF), and the third normal form (3NF), which are the "three normal forms" to be discussed in this article.

First Normal Form (1NF): Each column of a database table is required to be an indivisible atomic data item.

for example:

In the above table, the "family information" and "school information" columns do not meet the requirements of atomicity, so they do not meet the first normal form, and the adjustment is as follows:

It can be seen that each column after adjustment is indivisible, so it satisfies the first normal form (1NF);

Second Normal Form (2NF): On the basis of 1NF, the non-key attribute must completely depend on the candidate key (on the basis of 1NF, the partial functional dependence of the non-key attribute on the main key is eliminated)

The second normal form needs to ensure that each column in the database table is related to the primary key, not only to a certain part of the primary key (mainly for the joint primary key).

for example:

In the situation shown in the figure above, the same order may contain different products, so the primary key must be composed of "order number" and "product number".

However, it can be found that the product quantity, product discount, and product price are all related to the "order number" and "product number", but the order amount and order time are only related to the "order number" and have nothing to do with the "product number".

This does not meet the requirements of the second normal form. The adjustment is as follows, and it needs to be divided into two tables:

  

Third Normal Form (3NF): On the basis of 2NF, any non-main attribute does not depend on other non-main attributes (eliminate transitive dependencies on the basis of 2NF)

The third normal form needs to ensure that each column of data in the data table is directly related to the primary key, not indirectly.

for example:

In the above table, all attributes are completely dependent on the student number, so they satisfy the second normal form, but "teacher gender" and "teacher age" directly depend on "teacher name",

Instead of the primary key "student number", so the following adjustments need to be made:

  

In this way, the requirements of the third normal form are met.

Reprinted from: Relational Database Design: Popular Understanding of the Three Paradigms - Jing Yu No. 6 - Blog Park

Guess you like

Origin blog.csdn.net/qq_38786110/article/details/123419908