Browse By

How to Find Candidate Key(s)

As my final exam on Database Management Course closely approaching, I think I’m a bit forced (in a good way) to write some notes on the topics I’ve learned so far. This time it’s the notes on how to find candidate key of a given relation.

Lately after I started post my database notes on conflict and view serializability, and BCNF and 3NF check, I see increased visitors traffic to my blog. Some visitors actually visited my blog to find how to find candidate keys of a relation. I just have the time now to write this post, hopefully it’s not really too late.

Enough for the introduction, get your pencil and paper, let’s find that candidate keys!

Pencil and Paper? Can you just give me an App?

Sure, here it is:

If you don’t need to understand the process behind finding the candidate keys you can stop reading this blog post now. For those of you who still want to know how to find it manually, read on.

How to find it manually

Finding candidate keys is just as simple as applying some algorithm here and there. Here I post examples of different cases.

First example

WH -> S
HOS -> E

1. Find the attributes that are neither on the left and right side
> (none)

2. Find attributes that are only on the right side
> E

3. Find attributes that are only on the left side

4. Combine the attributes on step 1 and 3
> since step 1 has no attributes, it’s just WHO

5. Test if the closures of attributes on step 4 are all the attributes
> in our case, yes it is. Because with WH we can get S, and by HOS, we can get E.
So we have only one candidate key, that is WHO.

Second example

AB -> F
AD -> E
F -> G

1. C
2. EG
3. ABD
5. The closures of ABCD is ABCDEFG, so ABCD is our candidate key this time.

Third example

ABC -> D
D -> A

1. –
2. –
3. BC
4. BC
5. The closure of BC is only BC, we should find the relation exterior.
6. Find the relation exteriors, that is the attributes not included in step 4 and step 2.
> in this example it is AD
7. Now test the closures of attributes on step 4 + one attribute in step 6 one at a time.
> ABC closures are ABCD, so it is a candidate key
> BCD closures are ABCD, so it is also a candidate key
> so in this case we have two candidate keys, they are ABC and BCD.

Hoahm… these are too easy, harder examples please..

Allright, ready for some harder examples, here are they:

Hard example #1

DF -> C
BC -> F
E -> A
ABC -> E

Hard example #2

A -> BC
CD -> E
B -> D
E -> A


This is not the only algorithm of finding candidate key. Another way includes to find the attributes that are on both sides (see comment of RandomSpectrum on my other blog post to know about it). I suppose both algorithms are correct, it’s just a matter of personal preference.

I’m not going to post the answers here for the hard examples just to make it a bit harder. You can find it on different post: answer.

40 thoughts on “How to Find Candidate Key(s)”

  1. aravindhan says:

    thank you very much dude

    1. djitz says:

      You’re welcome, glad you find it useful! 😀

  2. Juseongkk says:

    Thank you a lot!

    I’ve studied with a book by Ulman, and the book never give that how to find candidate key!!!!

    You just save me lol

    1. djitz says:

      Hi Juseongkk,
      You’re welcome and very glad my notes helped you. 😀

  3. Ravikant says:

    thanks very very useful
    i have been frustated over BCNF & 3NF for 3 days
    these notes helped me a lot to understand the concept.

    1. djitz says:

      Hi Ravikant, I’m glad I could help you with my notes. 😀

  4. Ravikant says:

    i also need to check wheather a relation is in 1NF
    & 2NF .kindly if you can post the solutions of the above.
    i am thankful to you.
    thanking you in advance

  5. Swati says:

    Is the answer for 1st hard example is abcd and bdef?

  6. Murali R says:

    thank u.. u r great!

  7. Ankush says:

    Hi can you please mail me how to find the candidate keys for the harder ones?
    I am stuck with the first one.
    And in the second one Step 1 to Step 4 do not have any attributes. How to proceed?
    Why did you make it “harder” ? 🙂
    You should have posted the solutions for harder ones too 🙂

    1. djitz says:

      Hi Ankush, I’ve just sent the answer to your email.
      Looking at where you got the problem, you’re doing right so far, you only need to know how to tackle this problems.

      I purposely not posted the solutions so that people will give their try first. 😀

  8. dinesh says:

    u r genious mate… thanks heaps!!! u saved my life..

  9. soura says:

    please forward me the tricks for the harder ones.
    i have a exam on 18th.
    and if i get to know the trick … that’ll be great help

    thanks & regards

    1. djitz says:

      I’ve sent the answer to your email. 🙂

  10. Dipti says:

    Thanks for this explaination, I have my database exam approching and was frustrated with these concepts as I would be confused everytime… U r wonderful….

  11. FARA says:

    Thank You for the notes. Most of my class used it today to learn about the candidate key.

  12. saras says:

    U r my god!!!! Thanks a ton!!! This approach was very helpful!!! Your posts on Candidate keys and Normal Forms are quite enough for me to crack my final exam!!!

  13. pooja says:

    thank you

  14. sivaram says:

    It’s very nice algorithm

  15. kiran says:

    thnx a lot!!! i’m trying to solve the harder ones..

  16. kiran says:

    is the answer for 1st one is bdf?

    1. djitz says:

      no, it’s not. 😀
      just let me know if you need the answers..

  17. sean says:

    Hi djitz , yr step are better than what my lecturer had taught (exhaustive search). Can i have the answers for the harder question please ?

  18. sean says:

    Hi , may i know what is the rationale for Step 2 – Find attributes that are only on the right side . ? Thank a lot

    1. djitz says:

      It’s been awhile since I wrote this note, but I believe if the attributes are only on the right side, then they can’t be part of candidate key(s). 😀

  19. vidhya says:

    hi i tried for the harder one but not able to proceed after 7th step send me the solution along with how to solve it

  20. shyam says:

    vry vry thnx…
    please forward me the ans of harder 2nd ones.

  21. djitz says:

    @Vidhya and @Shyam, I’ve just emailed the solutions. 😀

  22. neha says:

    hii…very nice explanation..can you send me the solutions for the harder examples…thanks in advance..:)

    1. djitz says:

      @neha, just send an email to [email protected]. 🙂

  23. neha says:

    sent an email…pls fwd the solutions….

  24. Orkhan says:

    thanks a lot..ur post is really so useful ,tomorrow i have exam and now im really ready for any questions like this..
    harder #1: (DBEC) (DBEF) are candidate keys.
    harder #2: (DA) (DC) (DE) are candidate keys.
    thanks a lot again..

  25. Nikhil says:


    Very nice way to find out the candidate key…
    Thanks a lot 🙂 😀

    Pls send me the answers for the hard ones …

  26. huzefa says:

    great work man..!!!! i was jst digging out the internet for a good explanation of finding candidate keys … also on 3rd NF .. nd i got it from .. u !!! thnx frnd ..:)

  27. rahul says:

    thanks realy ur notes are too helpful can u also post on locking in transaction

    1. Trijito Santoso says:

      You’re welcome, glad you find it helpful. Unfortunately, I have no plan to create any notes about it right now.

  28. rahul says:

    Can u tel how to count no of candidate key from functional dependecoy
    plz post i ned it in my gate exam

  29. rahul says:

    Can u tel how to count no of super key from functional dependecoy
    plz post i ned it in my gate exam

  30. rahul says:

    Sir in ur hardr problem 2nd we hav a A and E as candidate key then why we calculate more candidate key without combination of A and E

  31. Sara says:

    Check this video …it may help you

Leave a Reply

Your email address will not be published. Required fields are marked *