So i have a relation R(A, B, C, D, E), with FD
{A->C, CE->B, BC->AD, D-E}.
And i want to normalize it to BCNF.
Since A->C and D->E violate BCNF. i substract C and E from ABCDE
which will be ABD. But how do i project the FD of the original Relation to the new ABD relation? I was told that the resulted FD on ABD will be
{AB->D, AD->B}
I don't quite understand it.
Any help would be appreciated!
The algorithm to project a set of dependencies over a decomposed schema is exponential, since one should calculate the closure of each subset of the attributes of the decomposed schema, and see which attributes of the closure belong to the decomposed relation. In simple cases, however, like that of your example, it is easy to check all the possible subsets (six):
A+ = AC
B+ = B
D+ = DE
AB+ = ABCDE (D is present in ABD, so AB → D is in the projection)
AD+ = ABCDE (B is present in ABD, so AD → B is in the projection)
BD+ = BDE
Related
I am trying to solve an exercise related with functional dependencies and database normalization. I have solved many exercises similar to this one but I can not solved this.
For a given a Schema with a single relation R(A, B, C, D, E, F), the set of all functional dependencies that holds is:
BC -> DC
B -> E
D -> EF
FC -> E
C -> A
F -> E
Normalize the relation R so it satisfies the 2NF AND all Functional dependencies are kept.
What I have done so far:
1) Find candidate keys: {BC} (I think there is a single candidate key)
2) Find a minimal equivalent set of dependencies
BC → D
B → E
D → EF
C → A
F → E
3) use C → A (A depends on C that is part of the candidate key, A is non prime)
R1(B, C, D, E, F), candidate keys BC
R2(C, A) candidate keys C
4) use B → E (E depends on B that is part of the candidate key, E is non prime)
R2(C, A) candidate keys C
R11(B, C, D, F) candidate keys BC
R12(B, E) candidate keys B
I do not like this normalization because the functional dependency F -> E can not be recovered. I am looking for a decomposition of R such that the second normal form is satisfied and no functional dependency is lost. Can anybody help me to find such decomposition?
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.
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.
I have been trying to understand the process of decomposing a relation but with no succes. I have no idea how it works and I can't figure it out. I have an example here if someone could explain me step by step how it works.
Consider schema R(A;B;C;D;E) with FDs
F = {AB -> CDE; AC -> BDE; B -> C; C -> B; C -> D; B -> E}.
1. Find all keys of R.
F = {AB -> CDE; AC -> BDE; B -> C; C -> B; C -> D; B -> E}
A+ = A
B+ = BCED
- it is not possible to deduce A from the other attributes -> A belongs to key
AB+ = ABCDE - a candidate key
AC+ = ACBDE - a candidate key
AD+ = AD,
AE+ = AE
ADE+ = ADE
I also don't understand what A+ signifies
What you've posted isn't decomposing a relation. It's finding the candidate keys. The candidate keys here are {AB, AC}.
Finding the keys is the second step in decomposing a relation. The first step is identifying all the dependencies. You're given all the functional dependencies, so you don't have to do that part here.
A+ means "the closure of the set of attributes A with respect to the set of functional dependencies F"--the set of attributes of F that can be determined by A.
This statement
it is not possible to deduce A from the other attributes -> A belongs
to key
should be
it is not possible to deduce A from the other attributes -> A belongs
to every candidate key
I am kind of confused on the notion of extraneous attributes and a proper decomposition into 3NF.
For example, I have the following relation:
r(A,B,C,D,E,F)
F = FD's
F = {A-> BCD, BC-> DE, B->D, D->A}
I want to compute the canonical cover in order to decompose it into 3NF using an algorithm. So I have to remove extraneous attributes from the FD's.
I computed A+. B+, C+, D+ (A+ = ABCDE, B+ = BD, C+ = C, D+ = AD)
I started trying to find extraneous attributes. First I looked at attributes in β
I tried to find if D is extraneous in
BC -> DE
and using BC+ I found D is extraneous (Since BC+ contains the attribute D).
So now my FD changed from BC -> DE to BC -> E
Now I tried to compute extraneous attributes for α.
I looked to see if B or C is extraneous in FD BC -> DE (Computing B+ and C+ led me to neither B or C being extraneous since none of them contain E).
I also looked at extraneous attributed in A -> BCD and found both B and C to be extraneous (Since A+ contains all attributes). So I was left with following:
A -> D
BC -> E
B -> D
D -> A
Sorry for the extremely long question, I just wanted to write down what I did.
I am confused as to if this is correct or if I am even doing this correctly. I am trying to follow some notes and some online references but it would be nice if someone could point out if I am doing this right and if not try and explain somewhat as to properly find extraneous attributes and decomposing.
Some of your closures are wrong (B+ = ABCDE, for instance due to B->D,D->A,A->BCD,BC->DE).
B and C are not extraneous in A->BCD. Indeed, the closure of A with respect to
{A -> D, BC -> E, B -> D, D -> A}
is AD rather than ABCDE.
So let us backtrack to your previous step:
{A-> BCD, BC-> E, B->D, D->A}
D is extraneous in A->BCD since A->B and B->D. We eliminate D from A-> BCD and obtain:
{A-> BC, BC-> E, B->D, D->A}
C is extraneous in BC->E. Indeed, B->D, D->A, A-> BC. Hence,
{A-> BC, B-> E, B->D, D->A}
Next we combine all fds with the same left-hand side:
{A-> BC, B-> DE, D-> A}
This set of functional dependencies does not contain redundant dependencies or extraneous attributes, and, hence, is a canonical cover.