Introduction to database systems paradigm shift problem

A method for solving a relational schema code

Simple methods seeking candidate codes:
(1) If attribute is not functional dependency concentrated there, it must be included in the candidate code; and
(2) if there is attribute is not functional dependency concentration of any right of functional dependency is present, it must contain in the candidate code; and
(3) if property appears only in the left set of functional dependencies, the attribute must be included in the candidate code.
(4) If attribute or tuple uniquely identifies the group, it is the candidate code;

After eleven combinations of the above-described methods and added culling determination key combination, i.e. has been elected and the rest of the rest of the key attributes, and can be determined

example:

(1) R <U, F >, U = (A, B, C, D, E, G), F = {AB -> C, CD -> E, E -> AA -> G }, seeking a candidate code?
  G only appears due to the right, they must not belong to the candidate code G;

  And B, D appears only on the left, so that B, D belonging to a certain candidate code;

  BD BD or closure, for BD the composition, in addition to G, BD may be combined with A, C, E

  Since the package itself look ABD ABD ABD, and AB -> C, CD -> E, A -> G, the closure is so ABD ABDCEG = U 

  Look BDC CD -> E, E -> A, A -> G, BDC from the package itself, the closure of the BDC BDCEAG = U

  Finally look BDE E -> A, A -> G, AB -> C, BDE itself from the package, the closure of the BDE BDEAGC = U

  Since (ABD), (BCD), (BDE) of the closure are so ABCDEG candidate codebook has three problems are ABC, BCD and BDE

Second, the method of converting 2nf

The general drawing can be solved, as long as the partially isolated non-primary attributes in part dependent on the key for a new relationship just fine.

Third, the method of converting 3nf (here written directly dependent holding and lossless conversion method decomposed)

 

1. Solving the minimum set of dependencies (removed individually for each dependency, the dependency determination whether to remove an influence on the entire set of dependencies), directly on the title

 Example 1: Relationship Model R <U, F>, where the U-= {C, T, H, R & lt, S, G},
F. = {The CS → G, C → T, TH → R & lt, the HR → C, the HS → R}, it is decomposed into functional dependency and maintain 3NF.
Solution: solved according to the algorithm     
(a) calculating a minimum set function F is dependent
      ① use of decomposition rules, all the functions are functions dependent on the right into a single attribute depends. Since all the function F is dependent on the right of a single attribute, without disassembling it.
      ② remove excess functional dependency F
      A. Provided CS → G redundant functional dependency, then remove the CS → G, to obtain:
      Fl = {C → T, TH → R & lt, the HR → C, the HS → R & lt}
      calculated (CS) F1 +:
      set X (0) = CS
      calculates X (1): F1 scanning respective functional dependency, the left part of functional dependency find CS or CS subset, to find a C → T-dependent function. Therefore, X (1) = X (0 ) ∪T = CST.
      Calculating X (2): F1 in scanning each functional dependency, or find a left portion of CST CST subset functional dependency, did not find any functional dependencies. Therefore, X (2) = X (1 ). Algorithm terminates.
      (CS) F1 + = CST does not contain G, it is not a function dependent CS → G redundant, can not be removed from F1.
      B. Set C → T redundant functional dependency, then remove the C → T, to give:
      F2 of = {the CS → G, TH → R & lt, the HR → C, the HS → R & lt}
      is calculated (C) F2 +:
      set X (0) = C
      Calculating X (1): F2 scan each functional dependency is not found as a function of the left portion of the C-dependent. Therefore, X (1) = X (0 ). Algorithm terminates. C → T it is not redundant functional dependency, it can not be removed from F2.
      C. Provided TH → R is a redundant functional dependency, then remove TH → R, to give:
      F3 = {the CS → G, C → T, the HR → C, the HS → R & lt}
      calculated (TH) F3 +:
      set X (0) = TH
      calculating X (1): F3 scanning in each functional dependency is not found as a function of the left portion dependent or TH TH subsets. Therefore, X (1) = X (0 ). Algorithm terminates. Therefore TH → R is not redundant functional dependency, it can not be removed from the F3.
      D. Provided HR → C redundant functional dependency, then remove HR → C, to give:
      the F4 = {the CS → G, C → T, TH → R & lt, the HS → R & lt}
      calculated (HR) F4 +:
      set X (0) = HR
      calculating X (1): F4 scanning in each functional dependency, the left portion of the function HR or HR dependent subsets not found. Therefore, X (1) = X (0 ). Algorithm terminates. Therefore, functional dependency HR → C is not redundant and can not be removed from F4.
      E. Provided HS → R is a redundant functional dependency, then remove the HS → R, too:
      the F5 = {the CS → G, C → T, TH → R & lt, the HR → C}
      is calculated (HS) F5 +:
      set X (0) = HS
      calculating X (1): the respective scanning function F5 dependence, the left portion of the function or HS HS subset dependency is not found. Therefore, X (1) = X (0 ). Algorithm terminates. Therefore HS → R is not redundant functional dependency, it can not be removed from F5. Namely: F5 = {CS → G, C → T, TH → R, HR → C, HS → R}
      ③ F5 remove excess left each functional dependency attribute (only the left portion of the check function is not dependent on the individual attribute), no extra left functional dependency property.
Therefore, the minimum functional dependencies as: F = {CS → G, C → T, TH → R, HR → C, HS → R}

2. For the minimum set in dependence dependency, if no attributes appear on both sides exists, these attributes are divided into a set of

3. If required lossless connected, directly add a candidate code

 

 

Known R (ABCDE), F = {A -> D, E-> D, D-> B, BC-> D, DC-> A} request remains functional dependency 3NF decomposition, and non-destructive to maintain connectivity and function-dependent decomposition 3NF
The first step: BG dependent decomposition problem, first find the minimum dependency set . First set value of minimum dependence of R, available F = {A -> D, E-> D, D-> B, BC-> D, DC-> A}
Step Two: depend not appear on both sides, divided into sub-sets aside, the remaining dependent variable subset . First, not be found without Now elements on both sides, then we are dependent on each obtained into subsets {AD} {ED} {DB } {BCD} {DCA}, it is also desired to maintain functional dependency decomposition 3NF
Third Step: To a lossless connection to add another subset of candidate do . R code to find a candidate of the so-called candidate code that is able to determine the relationship as a whole, we did not rely on the element in the right and both sides are emerging appear to be obtained by looking, you can find the CE does not appear on the right side, so the candidate code to {CE}. Therefore, the required non-destructive 3NF connectivity and the holding function for the decomposition dependency {AD} {ED} {DB } {BCD} {DCA} {CE}

 Third, turn BCNF

 The relational schema R <U, F> decomposed into basic steps is a BCNF

1). Obtained candidate keys, check whether the relational schema R in BCNF, if output to comply
2) Check whether the left portion of each of the relational schema containing candidate keyword, if a relationship S R mode do not meet the BCNF, certainly has X-> A belongs to F +, and X is not a candidate key S. Because S XA not include all of the properties, into the S {S1, S2}, where S1 = XA, S2 = (SA) X, calculates the minimum functional dependencies, and in place of {S1, S2} S substituted into the first step.
 
Fourth, the comprehensive example
Example 2. relational schema R <U, F>, there U = {A, B, C, D, E, F, G}, F = {B-> G, CE-> B, C-> A, CE -> G, B-> D, C-> D},
(1) The relational model is decomposed and remains functional dependency 3NF
(2) The relational model is decomposed into BCNF
 
 
The relational model is decomposed and remains functional dependency 3NF:
Suppose B-> G redundancy, (B) + = BD, no G which is not redundant.
Suppose CE-> B redundancy, (CE) + = CEGDA, no B which is not redundant.
Suppose C-> A redundancy, (C) + = CD, it is not redundant.
One can obtain the minimum functional dependencies Fm = {B-> G, CE-> B, C-> A, B-> D, C-> D}.
After the combination of the left portion of the same into one group: (BDG), (CEB), (CAD).
Therefore, the relational model is decomposed and remains functional dependency 3NF result of: (BDG), (CEB), (CAD).
 
The relational model is decomposed into BCNF:
First, a candidate obtains the relational model keyword (CE)
因为Fm={B->G,CE->B,C->A,B->D,C->D}。
Start looking left portion CE is not included in the relationship between mode, the first one of B-> G,
Divided into R1 = {(BG), {B-> G}} and R2 = {(ABCDE), {CE-> B, C-> A, B-> D, C-> D}}. Note that G can not appear in R2, the relation according to an alternative mode to be associated with the G.
Seeking the minimum of R1 and R2 functional dependencies, in accordance with the above-described algorithm steps are strictly carried out.
R1, R2 are the smallest functional dependencies itself.
Then decomposed, R1 consistent with BCNF, continue to decompose R2:
B-> D, left free of the code portion, is then decomposed R2 = {(BD), {B-> D}}, R3 = {(ABCE), {CE-> B, C-> A}}.
R2, R3 minimal functional dependencies are themselves.
The final result is then decomposed BCNF {(BG), (BD), (ABCE)}.

Guess you like

Origin www.cnblogs.com/buaawtt/p/11069910.html