Relations in 3NF format - database

I was doing some textbook questions which contain this following one.
Which of the following relations is in Third normal form (3NF)?
a) R(ABCD) FD's: ABD → C ; CD → A ; AC → B ; AC → D
b) R(ABCD) FD's: ABD → C ; A → B ; AB → C ; B → A
c) R(ABCD) FD's: AB → C ; ABD → C ; ABC → D ; AC → D
d) R(ABCD) FD's: AD → C ; D → A ; A → C ; ABC → D
I feel that all four choices are wrong but I do not have the answer to it. Could anybody help me with it? R represents relationship, FD is short term for functional dependency.
(Disclaimer: this is not from test/homework which gives any credit, I just want to make sure that I understand the concept correctly)

The way to prove something is in a certain NF form is by trying to break it. It is hard to describe why something is rather than is not in 3NF. That being said, could you tell me why you think each one does not satisfy 3NF so we can work from there?
This is what I've figured out:
b) Breaks 2NF since candidate key ABD can be broken down into AB which determines non-prime C.
c) Only candidate key is AB. AB -> C. D is determined through a transitive relationship ABC -> D. Breaks 3NF.
d) Candidate key BA determines C. But A -> C, therefore this breaks 2NF.
I could not find anything wrong with a, so that would be my guess to the right answer.

Let me explain it in simple words:
Condition for 3NF:
The non-prime attributes should be dependent only on super key
For option A,
By closure property,
AC+=ABCD
Thus A,C are prime attributes and B,D are non-prime attributes
Since all non-prime attributes are dependent on super key AC
The option A is in 3NF
For option B,
By closure property,
ABD+=ABCD
Thus,A,B,D are prime attributes and C is non-prime attributes
Since C, a non-prime attribute depends on AC which is not a super key,
option B is not in 3NF
For option C,
By closure property,
AB+=ABCD
Thus,A,B are prime attributes and C,D are non-prime attributes
Since D a non-prime attribute depends on AC which is not a super key
option C is not in 3NF
For option D,
By closure property,
AB+=ABCD
Thus,A,B are prime attributes and C,D are non-prime attribute
Since C, a non-prime attribute depends on AD which is not a super key,
option D is not in 3NF
Hope,it helps!!

Related

Is this in BCNF, 3NF or neither?

My doubt is for a given set of funtional dependencies F = { AE -> BCD, B -> E
}. Is this in BCNF or 3NF? It's a question from a test I have recently done and I would say that it is 3NF, but my teacher said it's neither 3NF nor BCNF. (I believe it is an error).
I have obtained as candidate keys AE and AB, and as in the first functional dependency the left side is a candidate key and in B -> E, E is contained in a candidate key, so it is in 3NF.
Is this in BCNF, 3NF or neither?
Assuming that all the attributes of the relations are A B C D and E, and that the only dependencies given are the two described (F), you are correct. Since the (only) candidate keys are correctly A E and A B, and since the functional dependency B → E has a determinant which is not a superkey, the relation is not in BCNF. Given one of the definitions of BNCF: “for all the non-trivial dependencies X → Y of F+, X is a superkey”, there is a theorem that shows that a necessary and sufficient condition for this is that the property of being a superkey holds for all the dependencies in F.
On the other hand, since E is a prime attribute, i.e. an attribute of a candidate key, the dependency B → E does not violate the 3NF, so that the relation is in 3NF. This, again, given one of the definitions of 3NF: “for all the non-trivial dependencies X → A in F+, then X is a superkey or A is a prime attribute”, is due to a theorem that says that this condition is equivalent to check, “for each functional dependency X → A1,...,An in F, and for each i in {1..n}, either Ai belongs to X, or X is a superkey or Ai is prime”. And this is satified by the two dependencies of F.
You need to use a definition of a NF when you claim/show that a relation is in it.
You don't actually say what all the attributes are. I'll assume the attributes are A through E. Otherwise, the CKs (candidate keys) are not what you say.
You are right in your argument against BCNF. You are using the definition that all determinants of FDs (functional dependencies) are out of superkeys. You found a counterexample FD B → E.
If it were an either-or question re BCNF vs 3NF you could stop there.
in the first functional dependency the left side is a candidate key and in B -> E, E is contained in a candidate key
You don't show that the table meets the conditions of either of the following definitions (from Wikipedia that happen to be correct) that a table is in 3NF if and only if:
both of the following conditions hold:
The relation is in 2NF
Every non-prime attribute is non-transitively dependent on every [candidate] key
for each of its functional dependencies X → A, at least one of the following conditions holds:
X contains A
X is a superkey
each attribute in A-X is prime
You seem to using definition 2 (but not saying so). You show bullet 2 holds for AE → BCD. Pointing out that E is prime in B → E seems to be part of showing that E-B is all prime. But you need to show every FD satisfies a bullet. Note that more FDs hold than the given ones. Armstrong's axioms tell you what all the FDs are.
In practice it can be easier to show a schema is in 3NF by applying a 3NF algorithm.

How to BCNF decompose when an attribute has no relation with any others

Assignment:
Consider a relation 𝑅(𝐴,𝐵,𝐶,𝐷,𝐸,𝐺,𝐻) and its FD set 𝐹 = {𝐴𝐵 → 𝐶𝐷, 𝐸 → 𝐷, 𝐴𝐵𝐶 → 𝐷𝐸, 𝐸 → 𝐴𝐵, 𝐷 → 𝐴𝐺, 𝐴𝐶𝐷 → 𝐵𝐸}.
Decompose it into a collection of BCNF relations if it is not in BCNF. Make sure your decomposition is lossless-join.
Explanation
Hi, I'm working on my database homework (relation design chapter).
I think I've commanded the basic process based on in-class examples.
However, the tricky part here is we have an attribute 'H' which has no relation with others, which confuses me deeply. How should I handle it?
Attempted answer
• We start from a schema: ABCDEGH, since H has no relations with any attribute, we decompose it into tables: H and ABCDEG
• The FDs for ABCDEG remains the same, therefore key is E.
• The FD D →AG violates BCNF (FD with non-key on LHS).
• To fix, we need to decompose into tables: ADG and BCDE
• FDs for ADG are { D → AG }, therefore key is D, therefore BCNF.
• FDs for BCDE are { B → CD,  E → D,  BC → DE, E → B, CD → BE }
• Key for BCDE is also E, and FD B → CD violates BCNF (FD with non-key on LHS).
• To fix, we need to decompose into tables: BCD and BE
• FDs for BCD are { B → CD } therefore key is B, therefore BCNF.
• FDs for BE are { E → B } therefore key is E, therefore BCNF.
• Final schema:  H, ADG, BCD, BE
What are your comments about my mistakes?
Your first bullet is wrong. If you go to a reference like a published academic textbook that has a correct BCNF decomposition algorithm then it will not have that step.

Concept Check -- Key Determination from Functional Dependencies

This is more of a concept check than anything, but suppose I have a relation R on attributes ABCD with the functional dependencies B -> ACD and C -> D. The solitary key for this relation is B, and a superkey for this relation is BC, correct?
The only candidate key in your example is indeed B. Any collection of attributes containing B will be a superkey, e.g., B itself, AB, BC or ABD.
candidate key is B.
As all the attributes can be derived from B, B becomes superkey..

Understanding 3NF: plain English please

I am working through an example problem in which we are trying to identify which of the following relations is in Third Normal Form (3NF). Here are the relations we are given:
R1(ABCD)
ACD -> B   AC -> D   D -> C   AC -> B
R2(ABCD)
AB -> C   ABD -> C   ABC -> D   AC -> D
R3(ABCD)
C -> B   A -> B   CD -> A   BCD -> A
R4(ABCD)
C -> B   B -> A   AC -> D   AC -> B
I know the answer is R1 is in 3NF, but I'm having a hard time understanding the steps to go about determining what violates 3NF. Can someone break it down in plain English for each of the relations? It would be extremely helpful if you can show me in steps how each relation might violate one of the 3NF rules:
X -> A, then A is a subset of X
X is a superkey
A is a part of some key for R
For R1, the first step I take is breaking it down into closures:
ACD+ = ABCD
AC+ = ABCD
D+ = C
ACD and AC are superkeys, which satisfy rule 2.
1. D -> C, but C is not a subset of D. Rule 1 violated.
2. D is not a superkey. Rule 2 is violated.
3. C is a part of some key for R. C is a part of AC and ACD. So, rule 3 is upheld?
Not sure if I'm even doing these steps right, so please break it down as simple as possible for someone struggling with these concepts. Thanks.
The best definition I've found for a relation that is in third normal form (3NF) is the following:
A relation schema R is in 3NF if, whenever a function dependency X -> A holds in R, either
(a) X is a superkey of R, or
(b) A is a prime attribute of R.
Now there are three definitions that need clarification, key,superkey, and prime attribute.
For the definitions we will use examples from the R1 relation to describe them:
R1(ABCD)
ACD -> B   AC -> D   D -> C   AC -> B
key: A key is the attribute that determines every attribute of the relation. In other words, it is the set of attributes that will give you all the other attributes of the relation that are not in the set. In relation R1 of the above example, the keys are AC and AD. Why is AC a key? Because by knowing attributes A and C you can determine the remaining attributes, B and D. Why is AD a key? The same reason. A and D will ultimately determine B and C.
superkey: A superkey is basically a superset of a key. A superkey will contain the key always and potentially more attributes. In the previous example, AC is a key. Thus AC, ACD, ACB, etc. are superkeys. Note that a key itself is a superkey.
prime attribute: A prime attribute is basically an attribute that is part of a key. Thus A and C are prime attributes as they are part of the key AC. Take note however, the difference between a key and superkey. For the super key ACB, B is not a prime attribute since B is not part of the key. Just think of a prime attribute as a subset of a key.
Now let's look at the four relations:
R1(ABCD)
ACD -> B   AC -> D   D -> C   AC -> B
R2(ABCD)
AB -> C   ABD -> C   ABC -> D   AC -> D
R3(ABCD)
C -> B   A -> B   CD -> A   BCD -> A
R4(ABCD)
C -> B   B -> A   AC -> D   AC -> B
For each relation we will write down the keys and the prime attributes. Then we will see if the definition is satisfied.
R1:
keys: AC, AD
prime attributes: A, C, D
ACD -> B: Left side is a superkey. Satisfies (a).
AC -> D: Left side is a key and thus a superkey. Satisfies (a).
D -> C: Left side is not a superkey. Does not satisfy (a). However, right side is a prime attribute. Satisfies (b).
AC -> B: Left side is a key. Satisfies (a).
Either (a) or (b) is satisfied in all cases. Thus R1 is in 3NF.
R2:
keys: AB
prime attributes: A, B
AB -> C: Left side is a key and thus a superkey. Satisfies (a).  
ABD -> C: Left side is a superkey. Satisfies (a).
ABC -> D: Left side is a superkey. Satisfies (a).
AC -> D: Left side is not a superkey. Does not satisfy (a). Right side is not a prime attribute. Does not satisfy (b).
Since (a) or (b) is not satisfied in all cases, R2 is not in 3NF.
R3:
keys: CD,
prime attributes: C, D
C -> B: Left side is not a superkey. Does not satisfy (a). Right side is not a prime attribute. Does not satisfy (b).
Since we have already found a case that does not satisfy either (a) or (b), we can immediately conclude that R3 is not in 3NF.
R4:
keys: C
prime attributes: C
C -> B: Left side is a key and thus a superkey. Satisfies (a).  
B -> A: Left side is not a superkey. Does not satisfy (a). Right side is not a prime attribute. Does not satisfy (b).
Again, we can stop here as the second case satisfies neither (a) nor (b). The relation R4 is not in 3NF.
A simplified expression of 3NF is "A relation is in 3NF if every attribute transitively dependent on a key is a key attribute."1 A key attribute is an attribute that's part of any candidate key.
R3 is one of the simpler ones to analyze with respect to 3NF.
R3(ABCD)
C -> B
A -> B
CD -> A
BCD -> A
The only candidate key is CD.
Is there a transitive dependency? Yes, there is: CD->A, and A->B. B is transitively dependent on the key.
Is B a key attribute? No, it's not; CD is the only key.
So R3 is not in 3NF.
R4 is similar. C is the only candidate key.
Is there a transitive dependency? Yes, there is: C->B, and B->A.
Is A a key attribute? No, it's not; C is the only key.
So R4 is not in 3NF.
In R1, the candidate keys are AC and AD.
Is there a transitive dependency? Yes, there is: AC->D, and D->C.
Is C a key attribute? Yes, it is.
So R1 is in 3NF.
"A New Normal Form for the Design of Relational Schemata", Carlo Zaniolo, in ACM Transactions on Database Systems, Vol. 7, No. 3, September 1982, p 492. More recent work uses prime attribute to refer to attributes that are part of any candidate key and non-prime attribute to refer to attributes that are not part of any candidate key.
Let me explain in simple words:
For the given relation,
R1(ABCD),the functional dependencies are:
ACD -> B
AC -> D
D -> C
AC -> B
Condition to be in 3NF
X->Y here X is a Super key when Y is non-prime attribute else it can be any attribute
Prime attributes are the attributes which belongs to the super key
Non-prime attributes are the attributes which do not belongs to the super key
Let us come back to relation R1,
AC+=ABCD
AD+=ABCD
ACD+=ABCD and
D+=DC
Thus,we get AD,AC,ACD as our Super keys
And A,C,D are prime attributes and B is a non-prime attributes
ACD->B
This Functional dependency is in 3NF as ACD is a super key and B is prime attribute
AC->D
This Functional dependency is also in 3NF as AC is a super key and D is prime attribute
D->C
This Functional dependency is also in 3NF as D is a prime attribute and C is also prime attribute
AC->B
This Functional dependency is also in 3NF as AC is a super key and B is non-prime attribute
Thus,the relation is not in 3NF only when non-prime attributes
does not depend on super key
Hope,this helps!
In simple english, here are the 3 Normal Forms:
1NF: The existence of "the key" ensures that the table is in 1NF(Key must be there).
2NF:It is required that "each" non-key attributes be dependent on "the whole key" to ensure 2NF.
3NF: further requiring that "each" non-key attributes be dependent on "nothing but the key" ensures 3NF.
Now, for this:
R1(ABCD) ACD -> B   AC -> D   D -> C   AC -> B
Look at these ACD -> B and AC -> B: clearly violates the 2NF condition. Forget 3NF, this relation is not even in 2NF. "the whole key"-->concept does not hold.
I think, you have proved the same using SET.

Convert To BCNF

I'm given the following relation:
R(A,B,C,D,E)
and the following Functional Dependencies:
F1 - AC -> D
F2 - D -> E
F3 - E -> A
I am attempting to convert this to BCNF form.
The first step I took was to figure out the possible keys for the relation.
Keys: ABC, BCD, BCE
Then I checked to see if the functional dependencies fit BCNF form, they do not.
So I attempted to decompose and got the following:
R1(A,C,D) AC->D Keys: AC
R2(D, E) D->E Keys: D
I believe at this point that the relations are in BCNF form and are lossless, but are not dependency preserving.
Does this seem like the right technique for this sort of thing? Is there a step or two I might have missed?
I believe there is an error in your BCNF. Between R1 and R2, you've lost B.
Keys, ABC, BCD and BCE are correct. (You require B, C and one of either A, D or E).
R1 (A, B, C, D), key ABC and R2 (D, E) with key D is a valid normalization.

Resources