MySQL three paradigms and anti-paradigm

<!-- Baidu Button BEGIN -->

1.  First Normal Form
Ensure atomicity of each column (field) in the data table.
If each field in the data table is the smallest unit of data that cannot be subdivided, the first normal form is satisfied.
For example: user user table, containing fields id, username, password
 
2. Second Normal Form
Taking the first normal form one step further, the goal is to ensure that each column in the table is related to the primary key.
If a relation satisfies the first normal form, and other columns except the primary key depend on the primary key, then the second normal form is satisfied.
For example: a user has only one role, and a role corresponds to multiple users. Then the data table relationship can be established as follows so that it satisfies the second normal form.
user user table, field id, username, password, role_id
role role table, field id, name
The user table associates the role table with the role id (role_id)
 
3. Third Normal Form
Taking second normal form a step further, the goal is to ensure that the columns in the table are directly related to the primary key, not indirectly related.
For example, a user can correspond to multiple roles, and a role can also correspond to multiple users. Then the data table relationship can be established as follows so that it satisfies the third normal form.
user user table, field id, username, password
role role table, field id, name
user_role user-role intermediate table, id, user_id, role_id
In this way, the relationship between the user table and the role table is established through the third table (intermediate table), and at the same time, it conforms to the principle of normalization, which can be called the third normal form.
 
4. Denormalization
Denormalization refers to improving the read performance of a database by adding redundant or duplicate data.
For example: add the field role_name to the user_role user-role intermediate table in the above example.
Denormalization can reduce the number of join tables in relational queries.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326122907&siteId=291194637
Recommended