[Database Principles] Relational Database Theory (5)

Normal Forms.

After decomposing, the criterion for judging the relational model is the paradigm of the model. The concept of the paradigm was first proposed by EFCodd, who successively proposed the three-level normative form of the relation:

  • First Normal Form 1NF
  • Second Normal Form 2NF
  • Third Normal Form 3NF

In 1974, Codd and Boyce jointly proposed a new paradigm: Boyce-Codd paradigm, referred to as BCNF. In 1976, Fagin proposed the fourth paradigm 4NF, and then someone defined the fifth paradigm 5NF. So far, the relational database specification has established A series of paradigms, the containment relationship between each other is as follows:
Insert picture description here
Insert picture description here

1NF.

The first normal form 1NF is the most basic normative form, that is, each attribute in the relationship is an indivisible atomic item. If all the attributes of the relational pattern R are atomic attributes, that is, each attribute is indivisible , then R is said to belong to the first normal form, denoted as R ∈ 1 NFR∈1NFR. 1 N F. .
We will first satisfy the relationship referred to as a normalized relational paradigm discussed only normalized relations in a relational database, all the non-relational model specification must be transformed into normalized relations, so 1NF is a relational model have at least conditions of. Disassembling the combined items in the non-standardized relationship can be transformed into a standardized relationship.
However, it is not enough for a relationship to only belong to the first normal form. For example, the following very classic relationship model SCD:
Insert picture description here
It also belongs to the first normal form, but there are many unsatisfactory points. Among the attributes, there are partial functional dependencies and There is a transfer function dependency. It is precisely because of these complex and indirect functional dependencies that the operation of this relational mode faces many problems. The way to overcome this point is to use projection operations to decompose the relation, remove the complicated functional dependencies, and make it a higher level. Paradigm transformation.

2NF.

Insert picture description here
In the relational model SCD given above, SNo+CNo is the main code, so SNo and CNo are the main attributes, and Age, Dept, SN and MN are non-primary attributes. According to the judgment conditions of 2NF, we found that SCD has non-primary attributes like SNo→Age that are partially functionally dependent on the main code, so SCD does not belong to 2NF. Through analysis, we can get the following two conclusions:

  • Eliminate the partial functional dependence of the non-primary attribute on the primary code from the 1NF relationship, and get 2NF;
  • If the main code of the relational pattern R is a single attribute, or the main code is a full code, then R∈2NF.

★2NF standardization algorithm.

Insert picture description here
[Example] Standardize SCD (SNo, SN, Age, Dept, MN, CNo, Score) to 2NF.

  • According to the algorithm, there is a partial functional dependence of non-primary attributes on the main code in SCD: (SNo,CNo)→SN|Age|Dept|MN, and SNo can completely determine the attributes on the right, so SCD is decomposed into SD(SNo, SN, Age, Dept, MN) and SC (SNo, CNo, Score), check again to get SD ∈ 2NF, SC ∈ 2NF, the decomposition is complete.

But 2NF is not our ultimate goal, it is not ideal yet, and it has the following shortcomings:
Insert picture description here
Insert picture description here

3NF.

[Definition] If a relational pattern R ∈ 2NF, and each non-primary attribute does not have a transfer function that depends on the main code of R , then we call R ∈ 3NF.
For example, the two relational patterns of SC and SD obtained by the previous decomposition, for SC In other words, the main code is (SNo, CNo), the non-primary attribute is Score, and the functional dependency is (SNo, CNo)→Score, so there is no non-primary attribute's transfer function dependence on the main code, so SC∈3NF; and For SD, the main code is SNo, but there are SNo→Dept, Dept→MN in the function dependency, so there is the transfer function dependence of the department head name MN on the main code SNo, so SD does not belong to 3NF and needs to be Further decomposition.

★3NF standardization algorithm.

Insert picture description here
Insert picture description here

★★3NF standardization algorithm Pro.

Insert picture description here
Insert picture description here
Insert picture description here
After the SCD relationship is standardized to 3NF, all anomalies in it have disappeared. However, 3NF only restricts the dependence of non-primary attributes on the main code, and does not restrict the dependence of the main attributes on the main code. If there is such a dependency, there may still be data redundancy, insertion exception, modification exception, and deletion exception. At this time, 3NF needs to be further standardized to eliminate the dependency of the main attribute on the main code. This is the new paradigm proposed by Codd and Boyce: BCNF.

BCNF.

Insert picture description here
Insert picture description here

BCNF normalization algorithm.

Insert picture description here
Insert picture description here
Insert picture description here

The normalization process of the relational model.

A relationship can be called a normalized relationship as long as its components are all indivisible atomic items, but this is only the most basic normalization requirement, namely 1NF. The purpose of normalization is to make the data structure reasonable, eliminate storage exceptions, and make data redundant. As little as possible, it is easy to insert, delete and modify. The basic principle of standardization is "one thing, one place", that is, a relationship only describes one entity or the connection between entities. If there is more than one entity, it is separated. Therefore, the so-called standardization is actually singularization-a relationship Represents an entity.

  • Project the 1NF relationship to eliminate part of the functional dependence of the non-primary attributes on the main code to obtain 2NF;
  • Project the 2NF relationship, eliminate the transfer function dependence of the non-primary attributes on the main code, and obtain 3NF;
  • Project the 3NF relationship to eliminate the partial functional dependence and transfer function dependence of the main attribute on the main code, so that the left part of the functional dependence is a candidate code of the relationship, and BCNF is obtained.

If a decomposition has lossless connectivity, it can guarantee that no data will be lost; if a decomposition has functional dependence, it can alleviate or solve various abnormal situations. As mentioned earlier, lossless connectivity and functional dependency retention are two mutually independent standards. The former does not necessarily have the latter, and vice versa. The normalization theory provides a complete set of algorithm for formulating pattern decomposition. According to this set of algorithms, it can be achieved: If the decomposition ρ is required to maintain functional dependence and lossless connection, it must reach 3NF, but it may not be able to reach BCNF.

Guess you like

Origin blog.csdn.net/weixin_44246009/article/details/108108937