Decomposing into BCNF - database

Suppose R = {A,B,C,D}
And FD = C→D,C→A,B→C
I am supposed to find:
1. the key(s)
2. the NF it is in
3. the BCNF (if possible and if not in already)
So here's what I've got so far:
the key is B since it transitively determines C which determines D and A.
it is in 2NF since dependancies are on the whole key
R1 = {B,C} R2 = {C, A, D}
So here's where I have an issue. The mark scheme says to decompose R into AC, BC, and CD. But why wouldn't my answer be right? Am I saying the FD is C -> {A,D} and if so is this difference to C -> A and C -> D?

When you're asked to compute the minimum cover of R, you're usually expected to answer like this.
C -> D
C -> A
B -> C
When you're asked to elevate R to BCNF, you're usually expected to answer like this.
B C
C AD
If you're not using a standard textbook, I can't give you any suggestions. Questions and answers written by TAs (teaching assistants) are particularly hard to understand. Sometimes they're just wrong.

Related

BCNF project FD on the result relations

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

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.

How to find multiple minimal/canonical covers or rearrange them to find new ones

I have a relation and function dependencies as follows:
R = (A, B, C, D, E)
F = (A -> B C,
B C -> D,
A C -> D E)
Now I am going to compute the minimal/canonical cover using this video.
So firstly I check if I have singleton right-hand sides in my FDs. No I don't, so I have to split them up. I.e. A -> B C is split into A -> B and A -> C. Similarly for A C -> D E.
So now I have...
F = (A -> B,
A -> C,
B C -> D,
A C -> D,
A C -> E)
Secondly, I check if any FDs have more than 1 LHS attributes. If they do, I see if any one of them can be eliminated by checking if their closure contains the other element. If it does, then we don't need that other element.
So for B C -> D, B closure is B and C closure is C. None of the closures contain the other attribute so we cannot eliminate B C -> D.
So now we move to A C -> D. A closure is ABCDE, we can instantly see that A's closure contains C. So C is and extraneous attribute and can be removed so our new set of FDs is...
F = (A -> B,
A -> C,
B C -> D,
A -> D,
A C -> E)
So now we move to the last one: A C -> E, again, A's closure is ABCDE, which contains C so we can eliminate the C from the FD. So our set of FDs is now:
F = (A -> B,
A -> C,
B C -> D,
A -> D,
A -> E)
Lastly, we check if there are any redundant FDs. We do this by going through each FD, covering it up, and seeing if the closure of its LHS contains its RHS.
So for A -> B, we cover it up and compute A closure, which is ACDE which doesnt contain B so we cannot eliminate A -> B. We do this for all FDs and we end up seeing that we can only eliminate A -> D because when we cover A -> D up and compute A closure it contains D, so we don't need A -> D
So now our new set of FDs are:
F = (A -> B,
A -> C,
B C -> D,
A -> E)
Now my question is:
Is my final set of FDs the correct minimal/canonical cover? Can it be written in another way? Also, In the video, it says that multiple canonical covers can exist for a given set of functional dependencies. How can I discover these?
Thank you for your time.
For eg.
X→YZ
Y→XZ
Z→XY
check out this answer with more than one possibility of minimal set
1:
X→Y,
Y→Z,
Z→X
2:
Z→Y,
Y→X,
X→Z
I checked all your steps and your final set is correct.
That said, I'm not sure about the multiple covers thing. The only difference between minimal cover and canonical cover is that a canonical cover is "allowed" to have more than one attribute on the right hand side, whereas minimal cover is not [source]. In this (trivial) sense you could obviously write the same set FDs in a different way.
On the other hand, I don't know if there could be two different sets of minimal covers with the same closure. I would say it is impossible, but that's just my intuition and I don't have elements to back it up.

Decomposing a relation

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

Database extraneous attributes and decomposition

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.

Resources