Decomposing a relation into 3NF, how do separate the relation? - database

Given a relation, R = ABCDE
and this set of FD's:
AB > C
DE > C
B > D
I'm able to find the candidate key ABE (correct?)
I need to decompose this relation R into 3NF.
What I don't understand is, by what measure do you decompose? I figure you take the candidate key and the FD's in consideration, but what is the specific process? All that I've looked at has been too dense for me to apply to this small problem.

ABE is the only candidate key.
Start with the tests for 1NF, and show yourself that the existing relation R satisfies 1NF. When you find a normal form that R does not satisfy, fix it.
For example, in testing for 2NF, you see that the FD AB->C is a partial key dependency. (ABE is the only candidate key; C is dependent on only part of that key.) Use projection to remove C from R.
R { ABE CD} is what we started with. After removing C by projection we have
R1 { ABE D}, and
R2 { AB C}
Repeat until all your tables are in 5NF. (R1 is not in 2NF; R2 is in 5NF.)

Related

Finding the Primary Key and Normalising a Relation with Functional Dependencies

I am studying for my databases exam and I've realized my professor did not teach a section of the normalization lecture notes, but glossed over them so I've been self studying and there is this example without solutions in the notes and I was wondering if I have been doing it right:
Given Relation R = {A,B,C,D,E,F,G,H,I,J}
And functional dependencies:
A,B -> C
A -> D,E
B -> F
F -> G,H
D -> I,J
Determine the primary key
Decompose R so it is in 2NF then show it in 3NF.
So, I got the primary key to be (A, B, D, F)
And then I tried to convert it to 2NF and I got relations:
(ABC), (DIJ), (ADE), (BF), (FGH)
And I honestly have no idea if this is right or how to then put it in 3NF... or if I've just skipped 2NF and already put it in 3NF. Any help?
It appears to me that you have skipped the NF2 and normalised the relation straight into the 3NF :)
The primary key for the original relation should be (A,B) as by inference rules (transitivity, such as A->D,E and D->I,J therefore A->I,J) it determines all other attributes. From this point onwards we have that:
FD1: A,B -> C
FD2: A -> D,E (Partial)
FD3: B -> F (Partial)
FD4: F -> G,H
FD5: D -> I,J
2NF (No partial dependencies allowed)
Now we can decompose the relation in three relations moving partial FDs to separate relations but preserving other FDs which might depend on those partial FDs, such as FD2 and FD5. This would give us the following results:
R1(A,D,E,I,J) -- FD2, FD5 (transitive)
R2(B,F,G,H) -- FD3 FD4 (transitive)
R3(A,B,C) -- FD1
Next, to achieve 3NF, transitive dependencies would have to be removed into separate relations in the same manner as NF2. Which, in turn, would result in the set of relations which you have already derived.
Good luck with your exams!

Multivalued dependency confusion

I am struggling with the concepts of 4NF and Multivalued Dependencies (MVDs).
I am looking at a supplementary book for the course I am currently taking and one of the examples is below.
The book states the asterisks refer to a unique key or a composite attribute key.
Given: R(A*,B,C*) and the set {(A,B):R,(B,C):R} satisfies the
lossless decomposition property.
Does the multivalued dependency B->>C hold?
Is B definitely a unique key?
Is R in 4NF?
I understand lossless decomposition - if you take the natural join of the two sets above - you are given the original dataset i.e in this case A,B,C.
But I just cannot grasp how to take the given information and prove/confirm that B->>C holds or if it does not.
I emailed my professor about my confusion and he just told me to look over his notes (which I've obviously done numerous times) and it's gotten me nowhere.
Does the multivalued dependency B->>C hold?
You have been told some things about MVDs. One of them is probably:
A decomposition of R into (X, Y) and (X, R − Y) is a lossless-join
decomposition if and only if X ->> Y holds in R.
In your case R is {A,B,C}, X is {B}, Y is {A} and R - Y = {A,B,C} - {A} = {B,C}. So a decomposition of R into (B,A) and (B,C) is a lossless-join decomposition if and only if {B,A} ->> {B,C} holds in R. But we are given that decomposition of R into (B,A) and (B,C) is a lossless-join decomposition. So {B,A} ->> {B,C} holds in R.
Is B definitely a unique key?
I can't make sense of that.
Maybe you are trying to say that we are given that {A,C} is a CK (candidate key) of R but that there might be other CKs and you are trying to ask whether the decompositionality means that {B} must also be a CK of R. Let's look for a counterexample. Pick a simplest example. Suppose R is {(a,b,c1),(a,b,c2)} = {(a,b)} JOIN {(b,c1),(b,c2)}. This agrees with R CK {A,C} & R MVD {B,A} ->> {B,C}. But b appears with c1 and c2 so {B} does not functionally determine all other attributes so {B} is not a CK of R. So that CK and that MVD do not force that {B} is a CK.
Is R in 4NF?
You have been told some things about 4NF. One is probably that:
A Table is in 4NF if and only if, for every one of its non-trivial
multivalued dependencies X ->> Y, X is a superkey
The MVD {B,A} ->> {B,C} is non-trivial. But to show whether R must be in 4NF or must not be in 4NF or that we can't tell, you are going to have to address possible sets of non-trivial MVDs that could hold in R and CKs that R could have.

BCNF -- Impossible to achieve?

Let R be a relation with Schema R(X,Y,Z)
and it's FDs are
{XY -> Z, Z -> Y}
I am not able to decompose it into BCNF .
Because r1(Z,Y), r2(Z,X) will lose FD XY -> Z and
R(X,Y,Z) itself is not the solution as Z->Y shows that Z should be a key ..
How to do this ???
Every conversion into BCNF may not be dependency preserving
We only need to give a counter example: Consider the following schema;
a b c and c->b
Clearly the above schema is in 3NF, because ab->c is a superkey dependency and ,from c->b we
can see that b-c=b, which is a subset of the primary key (such dependency is also allowed in 3NF).
But, the above schema is not in BCNF because c->b is neither super-key nor trivial dependency.
So we decompose above schema , keeping it lossless.
Only possible lossless decomposition is: ac and cb. (because,their intersection c is primary key for the 2nd table).
But clearly the dependency ab->c is lost.
Hence, proved.

How to normalize a table to BCNF form

I am trying to understand how to normalize a relation into BCNF form.
I know what is the definition of BCNF, and I know that in order to normalize it I need to eliminate every D -> X where D isn't part of a key candidate.
And to create a new tables of (D,X) and (S,X).
I also read this threads:
Normalisation into BCNF
BCNF Decomposition
Difference between 3NF and BCNF
But the problem I am facing is how to use the algorithm when X is part of the super key.
I will explain:
Assume we have this relation:
R = (a,b,c,d,e)
FD = { {a,b}->{c} , {a,b}->{d} , {a,b}->{e} , {d}->{b} }
Obviously, the only super key is (a,b). And clearly, d isn't a key candidate.
d->b violating the BCNF but we can't just take b out of the table since it is part of the super key.
So my question is: in this case, how can we normalize this relation into BCNF form?
Answearing my own question (with the great help of Jonathan Leffler):
This relation should be normalize into:
R1 = (a,b,c,e). super-key is (a,b).
R2 = (b,d). super-key is (d).
I.e. every time a scheme S have a FD D->X who violating the BCNF:
If D isn't part of the key the new tables are (D,X) and (S,X).
If D is part of the key the new tables are (D,X) and (S,D).
If both D and X are part of the key then the relation can not normalize into BCNF from.

how to produce a third normal form and BCNF decompositions

I'm trying to produce a 3NF and BCNF decomposition of a schema. I have been looking at the algorithms but I am very confused at how to do this.
If I have my minimal cover say: F' = {A->F, A->G, CF->A, BG->C) and I have identified one candidate key for the relation, say it is A. Then what exactly do I do?
I have been looking at examples, one which has the following:
F = {A → AB,A → AC,A → B,A → C,B → BC}
Minimal cover: F′ = {A → B,B → C}
And the final result was: (AB,A → B), (BC,B → C). How did they get to this?
If I have my minimal cover say: F' = {A->F, A->G, CF->A, BG->C) and I
have identified one candidate key for the relation, say it is A. Then
what exactly do I do?
F' is not a minimal cover: you have to combine A->F and A->G to A->FG
Even worth A cannot be a candidate key given F' since B does not belong yo the closure of A. A possible candidate key would be AB.
For 3NF you start with creating tables for each one of the dependencies in F', i.e.,
R1(A,F,G) R2(A,C,F) R3(B,C,G)
Next you check whether one of the tables contains a candidate key. Since B appears only on the left side of the dependencies, B should always be a part of a candidate key. The only table with B is R3 and it does not contain candidate keys (check it!). Hence, we add a new table R4 with a candidate key as attributes
R4(A,B)
Finally, we check whether the set of attributes of one of the tables is contained in the set of attributes of another table. This is not the case for our running example.
Hence, our 3NF decomposition is
R1(A,F,G) R2(A,C,F) R3(B,C,G) R4(A,B)
For BCNF you start with R(A,B,C,F,G) and look for BCNF violations.
For instance A->FG is a violation of BCNF because this dependency is not trivial and A is not a superkey. Hence we split R into
R1(A,F,G) and R2(A,B,C)
None of the relations obtained contains BCNF violations, so the process stops here.

Resources