In-depth use - relational data theory [including detailed examples + analysis]

✅ This part is more difficult, so I took some notes.



The teaching materials we use:
Please add a picture description


1. Examples of 1NF, 2NF, 3NF and BCNF

  1. The 1NF pattern that eliminates some functional dependencies must be ().
    A. BCNF
    B. 2NF
    C. 1NF
    D. 3NF

Answer: B, there may also be transitive dependencies, that is, not necessarily 3NF.


  1. If there is a relational schema R(A,B,C,D), and its data dependency set: F={(A,B)→C,C→D}, the normalization degree of relational schema R can reach ( ).
    A. 3NF
    B. BCNF
    C. 2NF
    D. 1NF

Answer: C, if there is a transitive dependency, it is not 3NF. Satisfy the rule of 2NF: every non-prime attribute completely depends on any candidate key . So it is 2NF.


  1. If there is no non-key attribute in the relational schema R, then R satisfies 3NF. ( )
    A. Right
    B. Wrong

Answer: A. Satisfy the rule of 3NF: each non-key attribute neither transitively depends on the code nor partially depends on the code. There are no non-primary attributes, obviously satisfying 3NF.


  1. If the primary key of the relational pattern R is a full key, it satisfies BCNF. ( )
    A. Right
    B. Wrong

Answer: A. Satisfy the rules of BCNF: every determinant (eg, X → Y, then X is the determinant) contains a code . Because its main key is the full key, if there is a functional dependency such as "X → Y", then X obviously contains the key, which satisfies the rules of BCNF.


  1. Functional dependency refers to the constraints that one or some relations of the relational schema R satisfy. ( )
    A. Right
    B. Wrong

Answer: B. From the definition 6.1 in the book and the "Note" below the definition, it can be known that functional dependency refers to the constraints that all relations of the relational schema R must satisfy.



2. Data dependent axiom system

2.1 Explanation of necessary basic terms

Some key definitions are as follows, you only need to know these nouns, and look back when doing the questions:

Functional dependency: Let R(U) be a relation schema on an attribute set U, and X and Y are subsets of U. If for any possible relation r of R(U), it is impossible for two tuples in r to have equal attribute values ​​on X but unequal attribute values ​​on Y, then it is called "X function determines Y" or " Y function depends on X", denoted as X→Y. X is called the determinant attribute group that this function depends on, also known as the determinant (Determinant) .

Logical implication (also referred to as implication for short): For a relation pattern R<U, F> that satisfies a set of functional dependencies F, for any relation r, if the functional dependence X→Y is established (that is, any two-tuple in r t, s, if t[X]=s[X], then t[Y] = s[Y]), then F logic implies X→Y.

Armstrong axiom system: Let U be the totality of attribute sets, and F be a group of functional dependencies on U, so there is a relation pattern R<U, F>. For R<U, F> there are the following inference rules:

 ① Reflexivity: If Y ⊆ X ⊆ U, then X → Y is implied by F.
 ② Augmentation: If X→Y is implied by F, and Z ⊆ U, then XZ→YZ is implied by F.
 ③ Transitivity: If X→Y and Y→Z are implied by F, then X→Z is implied by F.

Closure F + F^+F+ :In the relational pattern R<U, F>, the whole of the functional dependencies logically implied by F is called the closure of F, denoted asF + F^+F+

The closure XF + X_{F^+} of X on the functional dependency set FXF+: Let F be a set of functional dependencies on the attribute set U, X ⊆ U, XF + X_{F^+}XF+={ A | X→A can be derived from F according to Armstrong's axiom}, XF + X_{F^+}XF+is called the closure of the set of attributes X on the set of functional dependencies F.


For closure F + F^+F+ :Understanding of:

Please add a picture description


2.2 Algorithm 6.1 ⭐️⭐️⭐️

Lemma about closure (lemma: a proposition used to prove a theorem or solve a problem. There is no strict distinction between lemma and theorem): Let F be a set of functional dependencies on the attribute set U, X, Y ⊆ U, X→Y can be derived from F according to Armstrong's axiom, and the necessary and sufficient condition is Y⊆ XF + X_{F^+}XF+

The purpose of this lemma:
 ① The problem of judging whether X→Y can be derived from F according to the Armstrong axiom is transformed into finding XF + X_{F^+}XF+, determine whether Y is XF + X_{F^+}XF+problem of a subset of .
 ② If XF + X_{F^+}XF+= U, X is the candidate key of R<U, F>. 【Reference example 2】

X F + X_{F^+} XF+The following algorithm can be used to obtain:【Seek the closure XF + X_{F^+} of the attribute set X(X⊆U) on the functional dependency set F on UXF+]
 ① Order X ( i ) X^{(i)}X( i ) =X, i=0;
 ② Each function in F depends on Y→Z, if Y⊆X(i), letX ( i + 1 ) X^{(i+1)}X(i+1)= X ( i ) X^{(i)} X( i ) ∪Z.
 ③ YoungX ( i + 1 ) X^{(i+1)}X(i+1) X ( i ) X^{(i)} X( i ) , replace i with i+1, turn to ②;
 ④ IfX ( i + 1 ) X^{(i+1)}X(i+1)= X ( i ) X^{(i)} X( i ) ,X ( i ) X^{(i)}X( i ) is X.

Example 1:
insert image description here


Empirical method for finding the key of a given relational pattern: ⭐️ ⭐️
 ① If attribute A only appears in the right part of all functional dependencies, then it must not be included in any candidate key;
 ② If attribute A only appears in the right part of all functional dependencies
 ③ If attribute A appears in both the right part and the left part of the functional dependency, it may be included in the candidate code; ④ On
 the basis of the above, find the closure of the attribute .

Example 2:

insert image description here
insert image description here


2.3 Definition and Calculation of Minimum Dependency Set

Minimum dependency set (also known as minimal functional dependency set, minimum coverage): If the functional dependency set F satisfies the following conditions, then F is called a minimal dependency set:
 ① The right part of any functional dependency in F contains only one attribute .
 ② There is no such functional dependency X→A in F, so that F is equivalent to F-{X→A}. [Explanation: none of the functional dependencies in F can be derived from other functional dependencies in F]
 ③ There is no such functional dependency X→A in F, and X has a proper subset Z such that F-{X→A}∪{Z→A } is equivalent to F. [Explanation: The left part of each function dependency in F is the minimum attribute set (there is no redundant attribute)]

Solving steps for "Minimum Dependency Set":
 1. Right-handize all functional dependencies in F into a single attribute.
 2. Remove redundant attributes on the left side of all functional dependencies in F.
 3. Remove all redundant functional dependencies in F.

Example 3: Let R<U, F>, U=ABCD, function dependency set F = {A→BD, AB→C, C→D}. Seeking: The minimum set of functional dependencies of F

(1) Rightify all functional dependencies in F to a single attribute
F = {A→BD, AB→C, C→D} ⇒ F = {A→B, A→D, AB→C, C→D}
(2) Remove redundant attributes on the left side of all functional dependencies in F
because A + = { A , B , C , D } (including C ), B + = { B } A^+=\{A, B, C , D\}(including C), B^+=\{B\}A+={ A,B,C,D } ( including C ) , B+={ B } (excluding C), so in "AB→C", B is a redundant attribute.
So F = {A→B, A→D, A→C, C→D}
(3) Remove all redundant functional dependencies in F
because for "F = {A→B, A→C, C→D } ”,A + = { A , B , C , D } (including D ) A^+=\{A, B, C, D\} (including D)A+={ A,B,C,D } ( including D ) , so "A→D" is a redundant functional dependency
so F = {A→B, A→C, C→D}

Note: In the above (3), it can also be like this: for "F = {A→B, A→D, A→C}", A + = { A , B , C , D } (including D ) A^+=\{A, B, C, D\} (including D)A+={ A,B,C,D } ( including D ) , so "C→D" is a redundant functional dependency, so F = {A→B, A→D, A→C}

So the minimum dependency set F m F_m of FFmNot necessarily unique:

insert image description here
Why is there "C→A"? : Because through the minimum dependency set F m 1 F_{m1}Fm 1or F m 2 F_{m2}Fm 2Can restore F. C→A if it is not included in the minimum dependency set. Who will restore C→A?



3. Schema Decomposition with Lossless Connectivity

How to judge the lossless connectivity of a schema decomposition:

insert image description here
Example 4: (Examination does not require mastery)
insert image description here


Special case: Decomposition consists of only 2 patterns.

Theorem 6.5: Suppose R (U,F), there is ρ={R1, R2}, then for F, the sufficient and necessary condition for ρ to be lossless decomposition relative to F is: U1∩U2→U1-U2∈F + or U1 ∩U2→U2−U1∈F + . ⭐️ ⭐️

Example 5: (Examination requirements to master) ⭐️ ⭐️

insert image description here



4. Schema Decomposition with Functional Dependency

● Judging whether a decomposition preserves dependencies: use the method of judging whether two sets of functional dependencies are equivalent.

Example 6: (examination requirements to master)
insert image description here

Note: Retention-dependent decomposition ≠ connection without distortion. A dependency-preserving decomposition does not necessarily have connection indistortion. Conversely, a connection distortion-free decomposition does not necessarily have dependency preservation.



5. Convert to 3NF to preserve the decomposition of functional dependencies (algorithm 6.3 synthesis method)

● If F in R(U, F) is already the minimum dependency set, then follow the procedure below. If not, it is necessary to transform F into a minimal dependency set first. (The sample question in the picture below is already the minimum dependency set, and the test questions will be minimized, so you don’t need to do this action again)
insert image description here
In short:
 ① Find the minimum dependency set of F first, and then put the minimum dependency Concentrate those Fs with the same left part to merge [for example, merge "A→B, A→C" in F m1 in the above " 2.3 " legend into "A→BC"].  ② It is to combine the left and right sides of "→" to form a "sub-relationship". For example, decompose R<U, F> = R<{ABC}, {A→B, B→C}> into R 1 <U 1 , F 1 >, R 2 <U 2 , F 2 >, where R 1 <U 1 , F 1 > = R 1 <{AB}, {A→B}>, R 2 <U 2 , F 2 >=R 2 <{BC}, {B→C}>.

 ③ If there is “A→B 1 , A→B 2 ”, synthesize it like this: R 3 <{AB 1 B 2 }, {A→B 1,X→B 2 }>.



6. Decomposition into 3NF that has lossless connection and maintains functional dependence (algorithm 6.4)

insert image description here
In short: on the basis of "Algorithm 6.3", there is one more candidate code. In the figure, because "HSR" contains "HS", the results before and after the union are the same.



7. The result is the lossless decomposition algorithm of BCNF (algorithm 6.5) ⭐️⭐️⭐️

This exam requires mastery of: ⭐️ ⭐️ 【It may take some time to understand】

insert image description here

Example 7:

insert image description here


Example 8: [course C, teacher T, time H, classroom R, student S, grade G]
insert image description here

insert image description here
Explanation: HS is the main code. That initially selects "CS→G" because "CS" contains no keys. [The meaning of the code is the key, and the meaning of containing the key is to include the whole key (combination of attributes) and only a part of it is not included]. Of course, HR→C can also be decomposed first, or HT→R can be decomposed first. Although, the teacher said it is possible, but I think the decomposition order should be related to the "topological order", which requires drawing a directed node graph (as shown in the figure below, where the dotted line represents "indirect derivation line", and the solid line with a red circle represents "The line that will be decomposed next step" ).
insert image description here

insert image description here
Note: Although the above results are transformed into lossless decomposition of BCNF, the functional dependence HT→R is lost. This illustrates that lossless joins do not necessarily guarantee functional dependencies.



Eight, some supplementary examples

  1. Given the relation pattern R(A,B,C,D,E) and its functional dependency set F={A->D,B->C,E->A}, the candidate key of the relation pattern is ()
    A. AB
    B. AE
    C. BE
    D. ABE

Answer: C, because BEF += U BE_{F}^{+}=UBEF+=U,即 B E F + = { A , B , C , D , E } BE_{F}^{+}=\{A,B,C,D,E\} BEF+={ A,B,C,D,E } , that is, all attributes or attribute groups can be deduced through BE.


  1. It is feasible to derive the closure F + of F according to Armstrong's axiom. ( )
    A. Correct
    B. Wrong

Answer: B. Deriving the closure F + of F according to Armstrong's axiom is an NP-complete problem, so it is not feasible.


  1. When determining the candidate key of the relation schema R, if an attribute does not appear in the functional dependency set F, the attribute must be included in the candidate key. ( )
    A. Correct
    B. Wrong

Answer: A. If an attribute does not appear in the functional dependency set F, it means that the attribute is an "independent attribute" and has nothing to do with other attributes. in other words. It can neither deduce other properties (or groups of properties), nor can it be deduced by other properties (or groups of properties). The candidate key is the attribute (or attribute group) that can deduce all attributes (or attribute group). Obviously, if X does not appear in the functional dependency set F. Then X must be included in the candidate key. Because X can → X.


  1. Armstrong's axiom system is efficient and complete. ( )
    A. Correct
    B. Wrong

Answer: A. Theorem 6.2 in the book shows.


  1. The Armstrong axiom system includes [multiple choice]. ( )
    A. Reflexive law
    B. Augmented law
    C. Transitive law
    D. Associative law

Answer: ABC. Book definition 6.11.


  1. The minimal dependency set of F is not necessarily unique. ( )
    A. Correct
    B. Wrong

Answer: A. The previous "2.3" of this blog talked about it.


  1. If the relational schema does not satisfy 2NF, there must be "partial dependence of non-key attributes on candidate keys". ( )
    A. Correct
    B. Wrong

Answer: A. Satisfy the rule of 2NF: every non-prime attribute completely depends on any candidate key.


  1. The patterns obtained after lossless connection decomposition converted to BCNF using Algorithm 6.5 must also preserve functional dependencies. ( )
    A. Correct
    B. Wrong

Answer: B. Lossless connections converted to BCNF do not necessarily guarantee functional dependencies. The above examples have mentioned counterexamples.


  1. Assume that R(U, F) has decomposition ρ={R 1 , R 2 }, then F, ρ is a lossless decomposition relative to F. The necessary and sufficient conditions are: U 1 ∩ U 2 → U 1 -U 2 ∈ F + or U 1 ∩U 2 →U 2 -U 1 ∈F +
    A. True
    B. False

Answer: A. Theorem 6.5 in the book.

  1. There is a relational schema R(A, B, C, D, E, F), whose basic functional dependency set F={A→B, CD→A, BC→D, CE→D, AE→F}. Please:
    (1) Analyze the candidate codes of R. (No need to write the derivation process, just give the result)
    (2) Judge whether R reaches 3NF, and explain the reason.
    (3) If R does not reach 3NF, please decompose R into a pattern set p conforming to 3NF in a functionally dependent and lossless manner. (Give the result directly)
    insert image description here
    Explanation: FD means "Functional Dependency". In addition, the set of attributes that can uniquely identify a tuple in a relation is called the super key of the relation schema . An attribute can be used as a super key, and a combination of multiple attributes can also be used as a super key. Satisfy the rule of 3NF: each non-key attribute neither transitively depends on the code nor partially depends on the code.


Nine, after writing

● At the beginning of writing this blog. This part of the explanation on station B is very general, and many understandings are not in place. The definitions in the book are complicated. Many details of the PPT have not been expanded, making it difficult to collude. The teacher's Tencent replay has expired again. So the process of writing it still feels quite tricky.

● Relational data theory. This part is mainly about theory, and the teacher said that it is mainly about being able to use it. The author also mainly wrote how to use and solve problems correctly.

● If it is not enough, welcome to leave a message in the comment area for discussion.


⭐️ ⭐️

Guess you like

Origin blog.csdn.net/Wang_Dou_Dou_/article/details/124675862