Decomposing a relation - database

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

Related

Finding the candidate key

I have a relation R(A,B,C,D,E,G,H) which the functional dependencies :
AB -> CD
E -> D
ABC -> DE
E -> AB
D -> AG
ACD -> BE
H is not dependant on anything but its not in the dependencies.
My question is that is {HE} the candidate key as {HE}+ = R?
OR
E is the candidate key because {E}+ = R
{CDH}{HE}{ABH}{BDH}
are the candidate keys. So indeed, HE is Candidate Key, but not the only one who determines the hole Relation.
Seeing the functional dependencies it is in the first normal form (1NF)

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.

Decomposing into BCNF

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.

What happens when functional dependency is circular?

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.

Resources