Академический Документы
Профессиональный Документы
Культура Документы
1 of 11
http://www.rlvision.com/blog/method-for-determining-candidate-keys...
RLV Blog
Thoughts on technology and other
musings by an independent software
developer.
Method for determining candidate keys and highest normal form of a relation based on
functional dependencies
Posted on October 19, 2013 by Dan
For my advanced database systems course I needed to learn how to take a given relation and functional
dependencies, tell the highest normal form and then normalize it up to BCNF. Its actually not that hard, but there
are a lot of pitfalls to watch out for. Here Im going to show the methods I learned to solve the exam questions. I
need to give credit to the mentors and StinaQ for their help and tutorials!
R(A,B,C)
A B
B {A,C}
The trick is to draw boxes in order to visualize the dependencies (ignore the right hand side CK/NP box for now):
Example 1
Note that B->{A,C} was broken down to B->A and B->C thanks to the decomposition rule.
Lets try a more tricky one:
R(A,B,C,D,E,F)
A B
B A
{B,C} D
C E
15-09-2015 17:15
Method for determining candidate keys and highest normal form of a re...
2 of 11
http://www.rlvision.com/blog/method-for-determining-candidate-keys...
Example 2
Note that B and C in this relation is a composite key that together determine D. Thus we draw a box around both
of them to illustrate this dependency. And dont forget F, even though nothing is pointing to it!
15-09-2015 17:15
Method for determining candidate keys and highest normal form of a re...
3 of 11
http://www.rlvision.com/blog/method-for-determining-candidate-keys...
your boxes. In any of your composite CKs: does a part of it (i.e. a box inside the composite box) by itself
determine (point to) a non-prime attribute? If yes, NF2 does not pass (and the relation is thus in 1NF).
Is the relation in 3NF? Does the relation have any non-primes? If no, the relation is automatically in 3NF!
Otherwise: Is there a non-prime that determines (point to) another non-prime (resulting in a transitive
dependency because the last non-prime is determined indirectly)? If yes, 3NF does not pass (and the relation
is thus in 2NF).
Is the relation in BCNF? Are all the determinants also candidate keys? If yes, BCNF pass. This is easiest to
check by looking at the dependencies you were given (e.g. A->B and B->{A,C} in example 1) and check that
each key (left hand side of the arrow) is in your list of CKs.
Lets try this! Here is another example:
R(A,B,C,D,E)
A {B,C}
{B,C} A,D
D E
Example 3
First find the CK:s. We can easily see that {B,C} together determines A and D. Since D also determines E, starting
with {B,C} can determine all other attributes and is thus a CK. But wait! Since A determines {B,C} it must be a CK
on its own!
Now that we have the CK:s, we see that D and E are not part of any CK, so they are non-primary attributes.
All relations are already in 1NF, so we note this. How about 2NF? There is a composite key {B,C} so we need to
check if part of it can determine a non-prime on its own? Not a problem; this relation is in 2NF! 3NF say that a
non-prime must not determine another non-prime. Here is a problem, since D determines E. Thus 3NF does not
pass, and the relation only achieves 2NF!
Note the circle I draw to indicate the highest NF, e.g. 2NF in the above example. Since 3NF did not pass, the
highest NF is 2NF. If you dont do this, it is easy to make a mistake and pick the last one as the highest NF.
Tips
When you have finished drawing the boxes, do a final count of all attributes in R() and make sure they are all
present as boxes. Its very easy to forget the ones without any dependencies otherwise!
Remember that for example a 3NF relation is also in 2NF. If an exam question is is the relation in 2NF? and
you determine that the highest NF is 3NF, then the answer to the question is true. Dont mix up highest vs is
15-09-2015 17:15
Method for determining candidate keys and highest normal form of a re...
4 of 11
http://www.rlvision.com/blog/method-for-determining-candidate-keys...
in.
This page allows you to check that you have correctly determined the CKs and normal forms. Its a bit quirky to
use, but very convenient!
In the next post I will continue this tutorial and show how to normalize the relations to make sure they are in
BCNF!
Like
21
Tweet
12
This entry was posted in Tutorials and tagged databases, dependencies, education, normalization, rdbms. Bookmark the permalink.
45 Responses to Method for determining candidate keys and highest normal form of a relation
based on functional dependencies
Pingback: Method for normalizing a relation to BCNF based on functional dependencies | RLV Blog
Akshay says:
November 6, 2013 at 04:43
Joe says:
November 23, 2013 at 18:57
Dan says:
November 25, 2013 at 16:15
Both {A} and {B,C} are candidate keys in this example. Even if {A} looks smaller than {B,C}, {B,C} is still a minimal
CK, because if you were to remove either B or C from {B,C} it would no longer be able to determine the relation. Thus
it is minimal. {A,B,C} would not be a minimal key, because you could remove either A or B,C from it and it would still
determine the relation. Remember that we can have many CKs (but only one is chosen in the end as the primary key,
PK)
Reply
ram says:
January 9, 2014 at 06:26
ram says:
January 9, 2014 at 06:41
when Highest Normal form is asked,do we need to check normal form with all keys and select the normal form (or) select the
Highest normal form formed by one of its keys???
For example, if
A -> BCDEF
BC ->ADEF
B ->F
15-09-2015 17:15
Method for determining candidate keys and highest normal form of a re...
5 of 11
http://www.rlvision.com/blog/method-for-determining-candidate-keys...
D ->E is given.
then keys =A,{B,C}.
NF achieved by A is 2NF
NF achieved by {B,C} is 1NF. so what is Highest Normal form??? 1NF or 2NF is my doubt..
and some where i saw asking what is BEST normal form .can you clarify this also .
Thanks in advance.
Reply
Dan says:
January 9, 2014 at 14:15
ram says:
January 10, 2014 at 09:51
Thanks a lotnow I got it right.what about BEST normal form.are best and highest normal forms,both
same..i got doubt because finally,we select one of keys as primary keyso if BEST normal form is asked,we
need to choose a key that provides us highest normal form
Thanks in advance
Reply
Dan says:
January 10, 2014 at 13:42
Good question. Best is subjective, so if that is the question, I suggest to ask your teacher to clarify.
Theoretically highest is probably always best,but in some practical situations it is better to keep a
lower normal form because for example performance issues.
Reply
ram says:
January 10, 2014 at 19:04
okayThank you for spending time on my questions.i am learning a lot from your
blogsplease keep posting as many as possible.
Thank you,
Aniruddha says:
January 16, 2014 at 11:05
Shareena says:
January 26, 2014 at 17:40
15-09-2015 17:15
Method for determining candidate keys and highest normal form of a re...
6 of 11
http://www.rlvision.com/blog/method-for-determining-candidate-keys...
Reply
Dan says:
January 27, 2014 at 18:45
Sorry, but my understanding of redundancy in this context is limited. Perhaps some other reader can help?
Reply
Ksenia says:
February 13, 2014 at 11:06
Dan, thank you very much for such a great explanation! It is really hard to understand how to find CK in FD, but you made it
clear! super!
Reply
chiranjiv says:
February 26, 2014 at 13:48
Dan says:
March 7, 2014 at 17:48
Thank you very much for your detail article. Finally did I find something that is really useful and helps me understands
clearly about how to determine CK and NF from FDs.
Reply
prem says:
September 29, 2014 at 12:20
amit says:
October 11, 2014 at 04:24
hi prem,
15-09-2015 17:15
Method for determining candidate keys and highest normal form of a re...
7 of 11
http://www.rlvision.com/blog/method-for-determining-candidate-keys...
smita says:
October 21, 2014 at 16:56
A->BC
B->D
CD->E
E->A
Its highest normal fom is 3NF or BCNF
Reply
Hareish says:
January 7, 2015 at 06:20
CK:-A,BC,CD,E
All attributes in a relation is a key or part of key..then blindly say it is in 3NF.
its time for check BCNF,
in BCNF every determinent is CK then check one by one.
A determinent is CK.
B determinent is not a CK is a part of a key.
15-09-2015 17:15
Method for determining candidate keys and highest normal form of a re...
8 of 11
http://www.rlvision.com/blog/method-for-determining-candidate-keys...
conclusion:-highest NF is 3NF
Reply
Shaurya says:
May 8, 2015 at 21:22
Dear Sir
You said that non-primes do not exist in the CKs but both C and D do exist in the CKs sir could you
please explain this querry to me.
Thanking You
Reply
Shaurya says:
May 8, 2015 at 21:23
Shaurya says:
May 8, 2015 at 21:24
Hey
You said that non-primes do not exist in the CKs but both C and D do exist in the CKs sir could you
please explain this querry to me.
Thanking You
Reply
Marvin P says:
November 2, 2014 at 08:39
snopcoff says:
November 10, 2014 at 13:11
Diamond says:
November 14, 2014 at 04:34
What if you have a very complex set of FDs which you cannot put in diagram form? What do you do then? Example if you
have up to 8 FDs and only one of that 8 has one attribute on the LHS. All others have 2 or 3 attributes. Its going to be really
complex drawing the box diagram for such a situation. So what do you do?
Reply
Dan says:
November 15, 2014 at 08:44
If the drawings become too complex, then I think you need to really dig in to the theory behind functional
dependencies. There is probably some deep mathematical thinking behind it that will help you to a solution, but Im
not the right guy to ask.
Reply
15-09-2015 17:15
Method for determining candidate keys and highest normal form of a re...
9 of 11
http://www.rlvision.com/blog/method-for-determining-candidate-keys...
Pravin says:
December 24, 2014 at 18:45
Manasi says:
December 30, 2014 at 09:27
Hareish says:
January 7, 2015 at 06:05
Harish says:
January 7, 2015 at 06:28
suhaib says:
January 24, 2015 at 17:43
what if in a f.d,collection of prime and non prime attribute determines non prime attribute.Which normal form is that?
Reply
rashmi says:
March 16, 2015 at 05:28
firstly i would like to thank this blog and Dan sir for a simpler explanation to identify CNs.
i have a dought in ur example 1:, if a->b and b->{a,c} then according to formal definition of 3NF a->b,b->c so a->c. hence
this relation should not be in 3NF . please help me out from this confusion. hoping a solution from this blog. thanking you in
advance.
15-09-2015 17:15
Method for determining candidate keys and highest normal form of a re...
10 of 11
http://www.rlvision.com/blog/method-for-determining-candidate-keys...
Reply
Vaughan says:
April 24, 2015 at 22:56
The definition strictly says that no non-prime attribute should determine another non-prime attribute.
In this case, we can see that is true.
Reply
arpit says:
March 20, 2015 at 12:25
Vaughan says:
April 24, 2015 at 22:49
I think we have a bit of an error here. In Example 3, we list two different candidate keys. However, they are of different sizes.
The candidate key should be the minimally sized one.
Is the candidate key then just A?
Reply
Thank you very much! Your post helped me to get through the exams.
Reply
Anonymous says:
May 8, 2015 at 20:59
R(a,b,c,d,e)
Functional Dependencies : A->B
BC->E
ED->A
How to find a non-prime
Reply
Ilja I says:
June 2, 2015 at 00:18
SN says:
June 17, 2015 at 18:14
15-09-2015 17:15
Method for determining candidate keys and highest normal form of a re...
11 of 11
http://www.rlvision.com/blog/method-for-determining-candidate-keys...
Marvin P says:
July 6, 2015 at 08:01
RLV Blog
Proudly powered by WordPress.
15-09-2015 17:15