mysql database | three paradigms

Three paradigms

Three paradigms: Atomicity (not subdivided) / Unique primary key (all data depends on the primary key) / Each column field must have a direct relationship with the primary key rather than an indirect relationship

1. First Normal Form (1NF)

Each column of the database table is required to be an indivisible atomic data item.
for example:

img

In the above table, neither the "Family Information" and "School Information" columns meet the requirements of atomicity, so they do not meet the first normal form. The adjustments are as follows:

img

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

2. Second Normal Form (2NF)

On the basis of 1NF, non-code attributes must be completely dependent on candidate codes (on the basis of 1NF, partial functional dependence of non-primary attributes on the main code is eliminated)

The second paradigm needs to ensure that each column in the database table is related to the primary key, and not only related to a certain part of the primary key (mainly for the combined primary key).
for example:

img

In the situation shown in the figure above, the same order may contain different products, so the primary key must be a combination 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 the "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 adjustments are as follows and need to be divided into two tables:

img img

3. Third Normal Form (3NF)

On the basis of 2NF, any non-primary attributes do not depend on other non-primary attributes (eliminate transitive dependencies on the basis of 2NF)

The third paradigm needs to ensure that each column of data in the data table is directly related to the primary key, but not indirectly related.
3. Illustrate:

img

In the above table, all attributes are completely dependent on the student ID, so the second paradigm is satisfied, but the "class teacher gender" and "class teacher age" directly depend on the "class teacher name".

Instead of the primary key "student ID", you need to make the following adjustments:

img img

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

ps: If you change the name of the head teacher in the above table to the teacher number of the head teacher, it may be more accurate and more in line with the actual situation, but as long as you understand it.

Guess you like

Origin blog.csdn.net/weixin_40597409/article/details/115269022