Finding out 2NF for Functional Dependency - database

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), { } >

Related

How to decompose table to 3NF and BCNF

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.

Why is given example not in 3NF?

I have following example which I am trying to understand, where:
R = {A, B, C}
FD = {A->B, B->C, AB->C}
Prime key is A.
I know that this example is in 2NF, because prime key has only one element, but I dont understand why this example is not in 3NF.
C is functionaly dependent on AB, but B is not a key or part of an key. Is that the reason why it is not in the 3NF.
Thanks
In Relation R, the canonical cover of the set of dependencies FD is:
1. A → B
2. B → C
The reason is that the dependency A B → C can be derived from the others:
1. A → B (given)
2. AB → B (by enrichment of A → B)
3. AB → C (by transitivity of AB → B and B → C)
A candidate key of the relation is A, since its closure determines all the other attributes:
A+ = A
A+ = AB (by using A → B)
A+ = ABC (by using B → C)
No other attribute can be a key (B cannot determine A, C appear only on the rigth part of a dependency).
Remember that a schema is in Boyce-Codd Normal Form (BCNF) if and only if all the determinants of the functional dependencies of the canonical cover are superkeys, or, for the Third Normal Form (3NF), if and only if all the determinants of the functional dependencies of the canonical cover are superkeys, or a determinate is a prime attribute.
So, the schema is not in BCNF, neither in 3NF, since there is the functional dependency B → C in which the determinant B is not a key, and C is not a prime attribute. Finally, decomposing the schema in two relations:
R1 < (A B), { A → B } >
R2 < (B C), { B → C } >
we have two relations that are both in 3NF and in BCNF, and this decomposition preserves the functional dependencies of the original schema.

BCNF Decomposition and Keys

I've been looking to decompose the following relation from its present state, into BCNF with three functional dependencies.
Taking the maxim
the key, the whole key, and nothing but the key
I concluded that B-->C transitive functional dependency meant it was in 2NF, and should be decomposed to remove this into
This also, I think, should be in BCNF. However, my question is, does the A,B --> C FD break this - because it doesn't seem to match the 'nothing but the key', aspect of the maxim above? (And the 'B' part of the A,B --> FD is not a key attribute, rather 'B' is addition to the key)
You should note that the three dependencies:
A → B
A B → D
B → C
are not a canonical cover (A B → D can be simplified to A → D, given A → B). So, the canonical cover is:
A → B
A → D
B → C
and since the key is A, you are correct in decomponing the relation in:
R1<(B, C), {B → C}>
R2<(A, B, D), {A → B, A → D}>
Note that all the dependencies satisfy the BCNF definition, since the key of R1 is B, the key of R2 is A, and each depedency has its LHS which is a key.

DBMS 2NF and 3NF

Given
R(a, b, c, d, e, p, w)
two keys: (b, c, d) and (p).
F ={
{b,c,d} -> {a,e,p,w},
p -> {a, b, c, d, e, w},
w -> c
}.
Is R in the 3rd normal form?
R(a,b,c,d,e) and a set of FD
F={
Fdl: {a,b} -> {c,d,e}
Fd2: c -> {a,b,d,e}
Fd3: e-> a
}
Keys for R: {a,b} and {c}.
Is R in 2nd normal form?
I know that in 2NF there must not be any partial dependency of any column on primary key, as well as, in 3NF every non-prime attribute of table must be dependent on primary key.
But I don't get these example from the book.
Is R in the 3rd normal form?
No, R is not in 3NF as in 3NF we have two main properties: that if X->A then either X should be a super key or A should be a prime attribute. In FD3 w->c does not have these properties.
Is R in 2nd normal form?
Yes it is in 2NF, as in the RHS of the FDs the prime attributes are present.

Primary key of a relation with circular functional dependencies

I'm studying for my database exam and I'm not sure about one question which goes as follow:
Given the relation R={A, B, C, D, E, F, G, H, I} and the set of functional dependencies
F = { AB -> C,
A -> DE,
C -> AB,
B -> FGH,
D -> IJ,
D -> CBE
}
Under what (normal) form is this relation?
First, I know I have to find all candidate keys. Looking at the right, I see that every attribute of R appears on the right hand-side, so it is not trivial that any single attribute of R is a candidate key. So looking at the left hand-size, only A, B, C, D appear, so one or some of these attributes must appear in the candidate keys.
So using A, C and D works (details skipped), but using B alone doesn't. Considering using two-attribute ket is useless since any key that does not contain A, C or D won't "bring us back" to R. Exemple, BE allows us to find B, E, F, G, H, but then we can't proceed further, so not all attributes of R are found.
Also, using any combination with A, C, or D in it is useless since it contains a subset (a single attribute) which is part of a candidate key (a single attribute). Example, AB can be reduced to A, and then all attributes of R can be found.
What bugs me is AB -> C and C -> AB, which is a circular dependency. I thought of two possibilities:
C is the primary key and we can use it to find A and B (C -> AB);
AB can be reduced to A (as said above) and with it we can find C.
But it is very easy to see that AB must be unique and C must also be unique.
Let's only use AB -> C. We can have the following associations:
11 -> 1 (A = 1, B = 1, C = 1)
12 -> 1
But then, if we reinsert the rule C -> AB, we find:
1 -> 11
1 -> 12
which can't hold.
So C has to be unique.
Same thing if we only consider C -> AB, and then reinsert the rule AB -> C.
I'm starting to think that this is a trick and that the real primary key of this relation is ABC to ensure uniqueness of the combinations of AB and C. We would then have the following rules:
F'={
ABC -> DEFGH
D -> IJ
D -> CBE
}
Is this right? What about the other circular dependency, i.e. C -> D (first rule), D -> C (third rule), and C -> D (going back to first rule)? Do I simply not care about it?
If I don't care about it (and assuming the primary key is ABC), then it seems obvious that this table is not in 3NF since ABC determines D (which is a non prime attribute here), and D determines IJ, two non prime attributes. But it seems to be in 2NF because no non prime attribute (D, E, F, G, H, I, J) can be obtain using a subset of attributes of the candidate keys (ABC here).
Of course, I could consider the primary key to be A, C or D and split AB -> C and C -> AB in two separate relations, but I don't think joining those two tables will always respect the rules AB -> C and C -> AB. For example, if someone inserts a new row in one of the table, then the join could introduce an invalid row.
I am thinking too much? Am I going in the wrong direction?
Thanks for your help :)
AB -> C
A -> DE
C -> AB
B -> FGH
D -> IJ
D -> CBE
I will assume that the FDs in your relation are known to be exactly those in the the transitive closure of F. (What were you actually told about F vis a vis your relation?)
{} only determines trivially.
{A} determines DE, which determines IJCB, which determines FGH. CK.
{B} determines FGH. Not CK.
{C} determines AB. CK.
{D} determines IJCBE. CK.
Other singleton sets just determine trivially.
Proper supersets of A, C and D are not CKs.
Other proper supersets are of B,E,F,G,H,I,J, which cannot determine A, C or D. Not CKs.
That accounts for all subsets of attributes.
So the CKs are {A},{B} and {D}.
What bugs me is AB -> C and C -> AB, which is a circular dependency.
Why should this bug you? Just follow the rules you were given. Review the definition of CK and how to determine the CKs from FDs. Eschew non-technical terms.
the real primary key of this relation
"Primary key" is not a useful notion in normalization. (I can't make much sense of what follows.)
this table is not in 3NF since
I don't see any definition of 3NF being used in your reasoning. You seem to use a definition of BCNF, but not properly.
assuming the primary key is ABC
the candidate keys (ABC here)
Make up your mind. Is there one candidate key {A,B,C} or three candidate keys {A}, {B} and {C}? This is two different situations.
it seems to be in 2NF because no non prime attribute [...] can be obtain using a subset of attributes of the candidate keys
You mean no non-prime attribute is functionally dependent on a proper subset of attributes of any candidate key. You misquoted, then misused what you quoted as if it meant what you should have quoted.
Review the definitions of the normal forms and the definitions they depend on.

Resources