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
Third, turn BCNF
The relational schema R <U, F> decomposed into basic steps is a BCNF