I looked in Decomposing a relation into BCNF answers and tried it on my homework, but i don't get the correct answers, so i ask for help in BCNF decomposition
Consider R=(ABCDEG) & F={BG->CD, G->A, CD->AE, C->AG, A->D}.
I start pick A->D.
Now i got S=(AD), R'=(ABCEG).
I pick G->A.
Now i got S=(AD,AG) R'=(BCEG).
I pick C->G.
Now i think i need to get S=(AD,AG,CG) and R'=(BCE), But the answer in the end is (AD,AG,CGE,BC) .what went wrong? or perhaps, a better algorithm?
To convert a relation R and a set of functional dependencies(FD's) into 3NF you can use Bernstein's Synthesis. To apply Bernstein's Synthesis -
First we make sure the given set of FD's is a minimal cover
Second we take each FD and make it its own sub-schema.
Third we try to combine those sub-schemas
For example in your case:
R = {A,B,C,D,E,G}
FD's = {BG->CD,G->A,CD->AE,C->AG,A->D}
First we check whether the FD's is a minimal cover (singleton right-hand side , no extraneous left-hand side attribute, no redundant FD)
Singleton RHS: So we can write our FD's as { BG->C, BG->D, G->A, CD->A, CD->E, C->A, C->G, A->D}.
No extraneous LHS attribute: We can remove D from LHS of CD->A and CD->E since D is an extraneous attribute here (As we can get D from C since C->A and A->D). So we now have {BG->C, BG->D, G->A, C->A, C->E, C->G, A->D}
No redundant FD's: We note that there are a lot of redundant dependencies here. Removing them we have {BG->C, G->A, C->E, C->G, A->D}
Second we make each FD its own sub-schema. So now we have - (the keys for each relation are in bold)
R1={B,G,C}
R2={G,A}
R3={C,E}
R4={C,G}
R5={A,D}
Third we see if any of the sub-schemas can be combined. We see that R3 and R4 can be combined as they have the same key. So now we have -
S1 = {B,G,C}
S2 = {A,G}
S3 = {C,E,G}
S4 = {A,D}
This is in 3NF. Now to check for BCNF we check if any of these relations (S1,S2,S3,S4) violate the conditions of BCNF (i.e. for every functional dependency X->Y the left hand side (X) has to be a superkey) . In this case none of these violate BCNF and hence it is also decomposed to BCNF.
Note My final answer above is (AD,AG,CGE,BCG). The solution you expect is (AD,AG,CGE,BC) but that's wrong. The last relation here (S1) should also have the G attribute as shown above.
Give input: A relation R0 with set (Minimal) of FD's S0.
Output : A decomposition of R into a collection of relations, all of which are in BCNF
Algo:
R <- R0, and S <- S0
Repeat till R is in BCNF.
If there is a FD X -> Y that violates BCNF condition.
Compute {X}+ , and choose {X}+ as one relation as R1, and
another R2 as {(R - X + ) U X}
Map FD set S on R1 and R2 (determine FDs on R1 and R2).
Recursively repeat the algo on R1 and R2.
Rule:
1.Should be attribute preserving.
2.Should be lossless
3.Should be FD preserving
Example:
R(xyz) FD xy -> z; key : xy
z-> y;
Solve:
z-> y violet the BCNF condition.
So decompose relation R
{z}+= yz;
R1(yz) where key is z
and R2(xz) key is x
Related
This question was migrated from Stack Overflow because it can be answered on Database Administrators Stack Exchange.
Migrated 8 days ago.
Definition of BCNF:
Let R be a relation scheme with the attributes U and a set F of functional dependencies (hereafter FDs). Then R is in BCNF iff for any non-trivial FD X -> A in F+, X is a superkey, where X is a subset of U, A is in U and F+ is a closure of F.
According to the book Principles of Database and Knowledge Base Systems by Aho and Ullman, if F consists only of FDs with single attributes on the right, then we can replace F+ with F in the above definition, that is, the following proposition holds.
Proposition:
Let R be a relation scheme with the attributes U and a set F of FDs and suppose F consists only of FDs with single attributes on the right. If for any non-trivial FD X -> A in F, X is a superkey, where X is a subset of U, and A is in U, then R is in BCNF.
The book also says the same thing about 3NF.
Does the same thing hold true for 2NF? I write the details below.
Definition of 2NF:
Let R be a relation scheme with the attributes U and a set F of FDs. Then R is in 2NF iff for any non-trivial FD X -> A in F+, X is not a proper subset of any candidate key or A is a key attribute, where X is a subset of U, A is in U and F+ is a closure of F.
Under the above definition of 2NF, I want to know whether the following proposition holds.
Proposition:
Let R be a relation scheme with the attributes U and a set F of FDs and suppose F consists only of FDs with single attributes on the right. If for any non-trivial FD X -> A in F, X is not a proper subset of any candidate key or A is a key attribute, where X is a subset of U, and A is in U, then R is in 2NF.
I read a statement "Relation R in BCNF with at-least one simple candidate key is also in 4NF"
I don't think that it is always true but I am not able to prove it.
Can someone please help ?
The statement is true and this is the sketch of the proof taken from the paper "Simple Conditions for Guaranteeing Higher Normal Forms in Relational Databases", by C.J.Date and R.Fagin, ACM TODS, Vol.17, No. 3, Sep. 1992.
A relation is in 4NF if, for every nontrivial multivalued dependency X →→ Y in F+, X is a superkey for R. So, if a relation is in BCNF, but not in 4NF, then there must exists a nontrivial multivalued dependency (MVD) X →→ Y such that X is not the key. We will show that this is in contradiction with the fact that the relation is in BCNF and has a candidate key K constituted by a unique attribute (simple candidate key).
Consider the fact that, in a relation R(T), when we have a nontrivial MVD X →→ Y, (assuming, without loss of generality that X and Y are disjoint), then also the MVD dependency X →→ Z must hold in the same relation, with Z = T - X - Y (that is Z are all the other attributes of the relation). We can now prove that each candidate key must contain at least an attribute of Z and an attribute of Y (so it must contain at least 2 attributes!).
Since we have X →→ Y and X →→ Z, and X is not a candidate key, assume that the hypothesis is false, that is that there is a candidate K which does not contain a member of Y (and for symmetry, neither a member of Z). But, since K is a key, we have that K → Y, with K and Y disjoint.
Now, there is an inference rule that says that, in general, if V →→ W and U → W, where U and W are disjoint, then V → W.
Applying this rule to our case, since X →→ Y, and K → Y, we can say that X → Y. But this is a contradiction, since we have said that R is in BCNF, and X is not a candidate key.
In other words, if a relation is not in 4NF, than each key must have at least 2 attributes.
And given the initial hypothesis, that we have a relation in BCNF with at least a simple candidate key, for the previous lemma, the relation must be in 4NF (otherwise every key should be constituted by at least 2 attributes!).
I found a relation this way - CUSTOMER (NAME, STREET, CITY, STATE, ZIP)
That use abbreviating for each following way,
Name - N
STREET - R
CITY - C
STATE - T
ZIP - Z
And given F = {N->RCT, RCT->Z, Z->CT}
And question is decompose to 3NF and BCNF.
I decompose it to 3NF, In here I considered practical way,
R1(N,R,Z)
R2(Z,C,T)
Is it correct?
Or do I have to consider only given functional dependencies for decompose. If I think this way and decompose to 3NF, then the answer will be
R1(N,R,C,T)
R2(R,C,T,Z)
Please someone advice me which way the correct way.
Your first decomposition is not correct, while the second is. To decompose in 3NF, the first step of the “synthesis” algorithm requires to find a canonical cover of the set of dependencies, and then group the dependencies found in groups with the same left hand side.
Since there are no redundant dependencies or superflous attribute in your dependencies, we can start from the three dependencies, that have a different left hand side, producing three relations:
from N → RCT, R1 (N, R, C, T), with key N
from RCT → Z, R2 (R, C, T, Z), with key RCT
from Z → CT, R3 (C, T, Z), with key Z
then, noting that the third relation is completely contained in the second one, we can eliminate it. The final formal step of the algorithm requires that we check if in some decomposed relation is present a key of the original relation (otherwise a new relation with the key should be added). This is true, since Z is such a key, which is present in the second relation. So, the final decomposition is:
R1 (N, R, C, T), with key N
R2 (R, C, T, Z), with key RCT
Note that, by applying the “analysis” algorithms to find the BCNF we obtain a different solution:
R1 <(N, R, C, T),
{ N → RCT }>
R2 <(C, T, Z),
{ Z → CT } >
R3 <(R, Z),
{ } >
but in this decomposition the functional dependency CRT → Z is lost.
What is the BCNF decomposition for these dependencies?
A->BCD
BC->DE
B->D
D->A
What is the process to get to the answer?
We can first convert the relation R to 3NF and then to BCNF.
To convert a relation R and a set of functional dependencies(FD's) into 3NF you can use Bernstein's Synthesis. To apply Bernstein's Synthesis -
First we make sure the given set of FD's is a minimal cover
Second we take each FD and make it its own sub-schema.
Third we try to combine those sub-schemas
For example in your case:
R = {A,B,C,D,E}
FD's = {A->BCD,BC->DE,B->D,D->A}
First we check whether the FD's is a minimal cover (singleton right-hand side , no extraneous left-hand side attribute, no redundant FD)
Singleton RHS: We write the FD's with singleton RHS. So now we have FD's as {A->B, A->C, A->D, BC->D, BC->E, B->D, D->A}
No extraneous LHS attribute: We remove the extraneous LHS attribute C from FD BC->D and BC->E. So now we have FD's as {A->B, A->C, A->D, B->D, B->E, B->D, D->A}
No redundant FD's: We remove the redundant dependencies. Now FD's are {A->B, A->C, B->D, B->E, D->A}
Second we make each FD its own sub-schema. So now we have - (the keys for each relation are in bold)
R1={A,B}
R2={A,C}
R3={B,D}
R4={B,E}
R5={D,A}
Third we see if any of the sub-schemas can be combined. We see that R1 and R2 have the LHS so they can be combined. Similarly R3 and R4 can be combined. So now we have -
S1 = {A,B,C}
S2 = {B,D,E}
S3 = {D,A}
This is in 3NF. Now to check for BCNF we check if any of these relations (S1,S2,S3) violate the conditions of BCNF (i.e. for every functional dependency X->Y the left hand side (X) has to be a superkey) . In this case none of these violate BCNF and hence it is also decomposed to BCNF.
I have a relation looks like:
R = (X,Y,C,D)
and functional dependencies:
FD = {XY -> CD, YC -> D, D -> X}
I found out that the candidate keys are XY, YC, YD.
In this case, I have 3 candidate keys... so how do I use them when I decompose the relation into BCNF? I've never done decomposition of the relation with more than one key...
Thanks.
Relation 1: (Y,C,D)
Relation 2: (D,X)
#KeyM
1.Find out the FD that violates BCNF
In this case its D->X
2.Decompose into two relations R1,R2
R1(D,X) R2(D,rest)
3. Repeat 1,2 until all of the relations are in BCNF
Using this our solution is R1(Y,C,D) , R2(D,X)