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?
Related
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'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.
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 am trying to comprehend BCNF databasing and I can't quite wrap my head around it.
Consider the following relation:
R (A, B, C, D, E, F, G)
The following functional dependences hold:
A -> E, F
A -> G
A, B -> D
B -> C
E, F -> G
A -> D
How would I make it BCNF?
Speaking informally, in homework problems, you get to BCNF by
assuming you're in at least 1NF,
removing partial key dependencies to get to 2NF (at least),
removing transitive dependencies to get to 3NF (at least), and finally
removing remaining functional dependencies in which the left-hand side isn't a candidate key to get to BCNF (at least).
An example of a partial key dependency is the pair
AB->D
A->D
Since A alone determines D, the functional dependency AB->D has a partial key dependency.
An example of a transitive dependency is the pair
A->EF
EF->G
There's no guarantee that you can normalize a given relation to, say, BCNF and no higher. (This seems to cause a lot of confusion among university students on SO.) Removing partial-key dependencies to get to 2NF might leave all the relations in 5NF.
)We can use the Armstrong Axioms to get the F+
A -> D,E,F,G
B -> C (A,B -> D is ignored because A -> D)
E,F -> G
We can get the primary key(A,B).
According to the definition of BCNF, we have to separate A-> (E,F), B->C, A -> D and (E,F) -> G from the original schema.
(A,B) Primary key(A,B)
(B,C) Primary Key(B)
(A,D) Primary Key(A)
(A,E,F) Primary Key(A)
(E,F,G) Primary Key(E,F)
That's BCNF decomposition.
You can try this:
Table 1: A, B, D, E, F with composite primary keys (A, B) and foreign key( B) refer to table 2(B)
Table 2: B, C with B is primary key
Table 3: A, E, F, G with composite primary keys(A, E, F)
I am trying to decompose the following relationships in to 3NF:
A -> BCD
BC -> DE
C -> D
D -> A
So I eliminated the redundancy to get the canonical cover:
A -> BC
B -> E
C -> D
D -> A
And now I am trying to decompose this into 3NF.
Should I decompose into r1(A, B, C) r2(B, D), r3(C, D). Then what do I do with D -> A?
The fact that A -> B -> D -> A is throwing me off.
Given
A -> BCD
BC -> DE
C -> D
D -> A
to obtain a canonical cover we first remove D from BC->DE:
A -> BC
BC -> E
C -> D
D -> A
Next, we observe that C->D, D->A, A->BC and if we know B->E, then we also know C->E. Hence,
A -> BC
B -> E
C -> D
D -> A
3NF decomposition works as follows:
1) Create tables for each dependency in the canonical cover
R1(A,B,C) R2(B,E) R3(C,D) R4(A,D)
2) Determine candidate keys of R. If no candidate keys are contained in the tables of step 1, add a new table containing only attributes of a candidate key.
Here A is a candidate key and it is contained in R1 (and R4), so no new tables should be added.
3) If there is a table such that its attributes are a subset of attributes of another table, remove the "contained" table.
This is not applicable, so the 3NF decomposition remains unchanged.
As you see, circular dependencies are not problematic.