问题
I'm struggling to understand one aspect of the normalization process, I don't quite understand what to do with functional dependencies after I normalize a relation to 2NF (or 3NF). Let me describe it using an example.
The exercise from my school book asks to normalize the relation to 2NF and then to 3NF. We are given a relation
R=(ABCDEF) , F={AD->FE, BC->E, FEA->D, AC->DE, F->E, BD->A, F->C, ABC->AEF, B->F}
Following the book, I minimized the Functional Dependencies to
F = {AD->F, AC->D, BD->A, F->E, F->C, B->F}
Which should be correct, since I checked it a few times. Now we can find the keys :
{AB} and {BD}
Next, I can see that
B->F
Breaks 2NF, since a non-key attribute depends on a part of the key. So we need to "divide" our relation into two new tables :
R1 = (BFEC) and R2 = (ABD)
Here's where I get lost. Those new tables need to "inherit" the functional dependencies, so my idea was to do it like this :
F1 = {F->E, F->C, B->F} and F2 = {BD->A}
I was trying to base which relation gets which dependency just by looking at the attributes and then pairing them together. However, that leaves us with two functional dependencies from the original set :
AD->F, AC->D
That I have no idea where to fit. I tried to look up some theory behind it, but no luck so far.
Could someone explain to me how do I figure out the new functional dependencies for each new table that I create in the process of normalization?
Thanks.
回答1:
Suppose we want to losslessly decompose so that an FD (functional dependency) that holds in an original relation also holds in one of the components and so holds in their join. We can do this using the FD's attributes for one component while getting another component by dropping the determined attributes from the original, as long as the components share the attributes of a CK (candidate key) of one of them. You will have been told that that is so. Here for problematic FD B -> F that suggests decomposition {ABCDE} & {BF}, since common attribute set {B} is a CK of the latter.
So we need to "divide" our relation into two new tables : R1 = (BFEC) and R2 = (ABD)
That is not a lossless decomposition given these FDs, and it's not clear why you think it is. (The shared columns {B} don't include a CK of one of those components.)
(The term is not "divide", it is "decompose". It's not clear why instead of using the right term you used a different term that doesn't mean that, while even using scare quotes to show that you know it doesn't mean that, while not even saying what you do mean by it.)
Decomposing by splitting off some FD as described above might mean that some non-trivial FD that holds in the original doesn't have all its attributes in either component and so doesn't hold in them. (Notice also that the FDs that hold include all the ones implied by the listed ones, given by Armstrong's axioms, not just the listed ones.) Then although we would have a lossless decomposition, we couldn't check that the latter FD holds in the join of the components by checking that it holds in the components. This is called not preserving that FD. But it turns out that we can always normalize to 3NF while preserving FDs. That is why we don't normalize to a NF (normal form) by going through lower NFs or by randomly picking FDs, but instead use an algorithm specially designed to get to that NF while preserving FDs.
Find & follow an information modeling & relational database textbook. (Dozens are free online, also academic slides & courses.)
Here is Berstein's 3NF (which implies 2NF) synthesis algorithm from some slides by Ullman:
Given: a relation R and a cover F for the FDs that hold in R
1. Find C, a canonical cover for F
2. For each FD X -> Y in C, create a relation with schema XY
3. Eliminate a relation if its schema is a subset of another
4. If none of the schemas created so far contains a CK of R, add a relation schema containing a CK of R
来源:https://stackoverflow.com/questions/48373595/functional-dependencies-after-normalization