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 am having some trouble understanding Multi-Valued Dependencies. The definition being: A multivalued dependency exists when there are at least 3 attributes (like X,Y and Z) in a relation and for value of X there is a well defined set of values of Y and a well defined set of values of Z. However, the set of values of Y is independent of set Z and vice versa.
Suppose we have a relation R(A,B,C,D,E) that satisfies the MVD's
A →→ B and B →→ D
How does MVD play into A->B and B->D here? Honestly I'm not sure I really understand the definition after looking at example problems.
If R contains the tuples (0,1,2,3,4) and (0,5,6,7,8), what other tuples must
necessarily be in R? Identify one such tuple in the list below.
a) (0,5,2,3,8)
b) (0,5,6,3,8)
c) (0,5,6,7,4)
d) (0,1,6,3,4)
I would have thought AB is 0,1 and 0,5 and BD is 1,3 and 5,7. None of the answers have 0,1,3,5,7.
MVDs (multi-valued dependencies) have nothing to do with "at least 3 attributes". (You seem to be quoting the Wikipedia article but that informal definition is partly wrong and partly unintelligible.) You need to read and think through a clear, precise and correct definition. (Which you were probably given.)
MVD X ↠ Y mentions two subsets of the set S of all attributes, X & Y. There are lots of ways to define when a MVD holds in a relation but the simplest to state & envisage is probably that the two projections XY and X(S-Y) join to the original relation. Which also mentions a third subset, S-Y. Which is what the (binary) JD (join dependency) {XY, X(S-Y)} says.
Wikipedia (although that article is a mess):
A decomposition of R into (X, Y) and (X, R−Y) is a lossless-join decomposition if and only if X ↠ Y holds in R.
From this answer:
MVDs always come in pairs. Suppose MVD X ↠ Y holds in a relation with attributes S, normalized to components XY & X(S-Y). Notice that S-XY is the set of non-X non-Y attributes, and X(S-Y) = X(S-XY). Then there is also an MVD X ↠ S-XY, normalized to components X(S-XY) & X(S-(S-XY)), ie X(S-XY) & XY, ie X(S-Y) & XY. Why? Notice that both MVDs give the same component pair. Ie both MVDs describe the same condition, that S = XY JOIN X(S-XY). So when an MVD holds, that partner holds too. We can write the condition expressed by each of the MVDs using the special explicit & symmetrical notation X ↠ Y | S-XY.
For R =
A,B,C,D,E
0,1,2,3,4
0,5,6,7,8
...
A ↠ B tells us that the following join to R:
A,B A,C,D,E
0,1 0,2,3,4
0,5 0,6,7,8
... ...
so R has at least
A,B,C,D,E
0,1,2,3,4
0,1,6,7,8
0,5,2,3,4
0,5,6,7,8
of which two are given and two are new but not choices.
B ↠ D tells us that the following join to R:
B,D A,B,C,E
1,3 0,1,2,4
5,7 0,5,6,8
... ...
so R has at least
A,B,C,D,E
0,1,2,3,4
0,5,6,7,8
which we already know.
So we don't yet know whether any of the choices are in R. But we do now know R is
A,B,C,D,E
0,1,2,3,4
0,1,6,7,8
0,5,2,3,4
0,5,6,7,8
...
Repeating, A ↠ B adds no new tuples but B ↠ D now gives this join:
B,D A,B,C,E
1,3 0,1,2,4
1,7 0,1,6,8
5,3 0,5,2,4
5,7 0,5,6,8
... ...
And one of the tuples in that join is choice b) (0,5,6,3,8).
The way the question is phrased, they are probably expecting you to use a definition that they will have given you that is like another two in Wikipedia. One says that α ↠ β holds in R when
[...] if we denote by (x, y, z) the tuple having values for α, β, R − α − β collectively equal to x, y, z, then whenever the tuples (a, b, c) and (a, d, e) exist in r, the tuples (a, b, e) and (a, d, c) should also exist in r.
(The only sense in which this gives the "formal" definition "in more simple words" is that this is also a definition. Because this isn't actually paraphrasing it, because this uses R − α − β whereas it uses R − β.)
By applying this rule to repeatedly generate further tuples for R starting from the given ones, we end up generating b) (0,5,6,3,8) much as we did above.
PS I would normally suggest that you review the (unsound) reasoning that led you to expect "AB is 0,1 and 0,5 and BD is 1,3 and 5,7" (whatever that means) or "0,1,3,5,7". But the "definition" you give (from Wikipedia) doesn't make any sense. So I suggest that you consider what you were doing with it.
I have a relation R consisting of {A,B,C,D,E,F} and the below are the dependencies that follow :
{A} -> {C,F}
{C} -> {D}
{B} -> {E}
This has to be converted to 2NF and 3NF accordingly.
I just converted them accordingly.
Could you please validate and let me know if the below forms are valid ?
2NF :
{A,C,F,D}
{B,E}
3NF :
{A,C,F}
{C,D}
{B,E}
The conversion in 3NF is not a correct one, since you have a decomposition that is not “data preserving” (that is, if you have an instance of the relation R, and project it over the attributes of the decomposed relations, when you do the natural join of them you obtain a relation which is different from R).
The reason is that the (only) candidate key of R is {A,B}, and this two attributes must be both present in a decomposed relation. So, in the synthesis algorithm to decompose a schema in 3NF, the last step says that if no candidate key of the original relation is present in any decomposed relation, one must add a schema with a key. So the correct decomposition is the following:
R1 < (A C F), { A → C F } >
R2 < (B E), { B → E } >
R3 < (C D), { C → D } >
R4 < (A B), { } >
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