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:Now there are three definitions that need clarification,
key
,superkey
, andprime attribute
.For the definitions we will use examples from the R1 relation to describe them:
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 areAC
andAD
. Why isAC
a key? Because by knowing attributesA
andC
you can determine the remaining attributes,B
andD
. Why isAD
a key? The same reason.A
andD
will ultimately determineB
andC
.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. ThusAC
,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. ThusA
andC
are prime attributes as they are part of the keyAC
. Take note however, the difference between a key and superkey. For the super keyACB
,B
is not a prime attribute sinceB
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:
For each relation we will write down the
keys
and theprime attributes
. Then we will see if the definition is satisfied.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 in3NF
.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 in3NF
.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 in3NF
.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 in3NF
.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:
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.
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)
The only candidate key is CD.
So R3 is not in 3NF.
R4 is similar. C is the only candidate key.
So R4 is not in 3NF.
In R1, the candidate keys are AC and AD.
So R1 is in 3NF.
Let me explain in simple words:
For the given relation, R1(ABCD),the functional dependencies are:
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
Let us come back to relation R1,
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
AC->D
D->C
AC->B
Hope,this helps!