SQL Functional dependencies - database

Suppose X1 → Y1 and X2 → Y2
Is it true that X1 ∩ X2 → Y1 ∩ Y2?
How about X1 ∪ X2 → Y1 ∩ Y2?
I've been thinking about this for a couple of hours and am really stuck. Maybe the second one is true because anything both in Y1 and Y2 will be dependent on at least one of X1 or X2.

The first formula is obviously false. A very simple example to show this is:
R(A,B,C,D)
A B → C D
B E → D F
from this one cannot infer that B → D in any way, and in fact the following instance satisfies the two above dependencies, but not the third one (for the same value of B, there are two different values of D):
A B C D E F
----------------------
a1 b1 c1 d1 e1 f1
a2 b1 c1 d2 e1 f1
The second formula is, on the other hand, true, and this can be proved by using the Armstrong’s Axioms.

Related

Finding the canonical cover? [duplicate]

I have a relation r(A,B,C,D,E,F) satisfying:
AB->C
C->A
BC->D
ACD->B
BE->C
CE->FA
CF->BD
D->EF
I need to find the canonical cover for this relation?
I know the algorithm to find the canonical cover. However in the algorithm, we need to find the extraneous attributes. Is there an algorithm to find extraneous attributes?
The algorithm to find extraneous attributes is the following:
let F the initial set of functional dependencies
assume that each dependency F is in the form A1, A2, ..., An -> B
for each functional dependency A1, A2, ..., An -> B in F with n > 1
for each Ai
if B ∈ ({A1, A2, ..., An} - Ai)+
then Ai is an extraneous attribute and must be removed from the left hand side
Note that the closure of the remaining attributes must be computed by considering all the dependencies of F, including the dependency under examination (this can be counterintuitive).
For instance, applying this algorithm to your example, starting from the dependencies:
{ A B → C
A C D → B
B C → D
B E → C
C → A
C E → A
C E → F
C F → B
C F → D
D → E
D → F }
In A C D → B, A is estraneous since {C D}+ = (A B C D E F), while in C E → A, E is estraneous since {C}+ = (A C).

How to find the extraneous attributes of functional dependency?

I have a relation r(A,B,C,D,E,F) satisfying:
AB->C
C->A
BC->D
ACD->B
BE->C
CE->FA
CF->BD
D->EF
I need to find the canonical cover for this relation?
I know the algorithm to find the canonical cover. However in the algorithm, we need to find the extraneous attributes. Is there an algorithm to find extraneous attributes?
The algorithm to find extraneous attributes is the following:
let F the initial set of functional dependencies
assume that each dependency F is in the form A1, A2, ..., An -> B
for each functional dependency A1, A2, ..., An -> B in F with n > 1
for each Ai
if B ∈ ({A1, A2, ..., An} - Ai)+
then Ai is an extraneous attribute and must be removed from the left hand side
Note that the closure of the remaining attributes must be computed by considering all the dependencies of F, including the dependency under examination (this can be counterintuitive).
For instance, applying this algorithm to your example, starting from the dependencies:
{ A B → C
A C D → B
B C → D
B E → C
C → A
C E → A
C E → F
C F → B
C F → D
D → E
D → F }
In A C D → B, A is estraneous since {C D}+ = (A B C D E F), while in C E → A, E is estraneous since {C}+ = (A C).

Is A → B the same as B → A when speaking of functional dependencies?

This might very simple but I just had to check with you guys.
When it comes to databases, does the arrow in literature imply vise versa on equality?
Meaning, is A → B considered the SAME as B → A, in particular when it comes to databases and functional dependencies?
Please read the reference(s) you were given for FDs (functional dependencies).
A FD is an expression of the form "A → B" for sets of attributes A & B. So if A and B are different, A → B is a different FD than B → A.
For a relation value or variable R, "A → B holds in R" and "A → B in R" say that if two R tuples have the same subtuple for A then they have the same subtuple for B.
Is A → B in R equivalent to B → A in R? If A and B are the same set, then yes. But what if they aren't?
X Y
a 1
b 1
{X} → {Y} holds in that relation value. {X} <> {Y}. Does {Y} → {X} also hold?

Determining BCNF violations

So I have a relation schema with FD's that look like this:
R(A,B,C,D): AB -> C, B -> D, CD -> A, AD -> B
Now I'm trying to find all the BCNF violations and then decompose the tables. I computed the left hand side of all the FD's and found this:
AB+ = {A, B, C, D}
B+ = {B, D} <- violation
CD+ = {C, D, A, B}
AD+ = {A, D, B, C}
So I decompose the table to look like this:
R1 (B, D)
R2 (A, B, C)
The only problem is that I'm not sure if this is all I have to do when it comes to decomposing the tables or if I have to do more. I'm mainly confused about the AB, CD, and AD parts.
In your example, B → D is in effect the only dependency that violates the BCNF, since in all the other depedencies the left hand side is a key (actually all the keys of the relation are (A D), (A B), (B C) and (C D)).
So, you can decompose by splitting the original relation R in R1, containing B+, that is BD, and R2, containing R - B+ + B, that is ABC, as you have correctly found.
Then one should apply again this process if in any of the decomposed relation there is some dependency that violates the BCNF. But this is not the case, since the only dependency in R1 is B → D, with B the only key, and with the dependencies AB → C and BC → A in R2, that has keys AB and BC.
At this point can terminate the process since R1 and R2 are both in BCNF. But we should note also that this decomposition does not preserve the dependencies, since CD → A and AD → B have been lost.

Can BCNF decomposition preserve all functional dependencies given F = {AB -> E, BC -> G, C-> BG, CD->A, EC->D, G->CH}?

Given F = {AB -> E, BC -> G, C-> BG, CD->A, EC->D, G->CH}, perform a BCNF decomposition and check whether it preserves all functional dependencies.
The minimal cover is R = {AB->E,C->B,C->G,CD->A,EC->D,G->C,G->H}
I performed on R a BCNF decomposition(it is a must to perform on the minimal cover) and I stayed with two dependencies of which one is preserved and one isn't preserved. In the answers they tell me that all of the dependencies are preserved. Can please anyone confirm this?
ABE, CBG, CDA, CED, GCH are in BCNF and loosless join and dependency preserving. relation keys are in bold
There is always a possibility to add a new relation for preserving a dependency as long as this new relation is in BCNF.
Starting from the canonical cover, we can see that the determinant of A B → E is not a superkey and so R can be replaced by:
R1 < (A B E) , { A B → E } >
and:
R2 < (A B C D G H) ,
{ G → C
G → H
C → B
C → G
C D → A
A B C → D } >
In R2 the determinant of G → C is not a superkey and so R2 can be replaced by:
R3 < (B C G H) ,
{ G → C
G → H
C → B
C → G } >
and:
R4 < (A D G) ,
{ D G → A
A G → D } >
So, the final decomposition is:
R1 < (A B E) ,
{ A B → E } >
R3 < (B C G H) ,
{ G → C
G → H
C → B
C → G } >
R4 < (A D G) ,
{ D G → A
A G → D } >
and the dependency:
{ C E → D }
is not preserved.

Resources