[Technokarak Explains] How to Find Candidate Key in Database Relation R

How to Find Candidate Key in Database Relation R is probably a new and unusual topic for the kind of Blog Technokarak is. But for more than a year I am writing about stuff related to gadgets, SEO, Blogging Tips and other technical things. The article is titled as [Technokarak Explains] which signifies something related to educational purpose and will surely help lots of students across the globe. Now coming to the Candidate Keys in Database Relation R which plays a very important role in designing of any database whether for small application or for big enterprise. In this article I will show how to find candidate keys in Database Relation R and why it is very important to learn it.

How to Find Candidate Key in Database Relation R

How to Find Candidate Key in Database Relation R

Why you should Learn to Find Candidate Key in Database Relation R

The database is the heart of any software and determines whether a software is good or bad. Simple if your database is not designed properly your software or application will go to face a lot of problems. In the database there is a term or rather a concept known as “Normalization” that helps in removing redundancies/anomalies from your database. There are lots of normal forms like 1NF, 2NF, 3NF, BCNF, 4NF and 5NF. Rules to find which relation is in which normal form is very simple but requires a candidate key to decide that. Once you know all the candidate keys you can decompose any Database Relation in any normal form you want.

How to Find Candidate Key in Database Relation R

Finding Candidate key in Database Relation R is very simple and requires you to find the attribute closure of Attribute. For example say you have some FD’s given to you and among those FD’s 5 attributes are present {A, B, C, D and E} and set of FD’s are as follows:

  • AB->CD
  • AC->BED
  • D->A

Now to find candidate keys in above mentioned set of FD’s you first need to start by finding out closure of each attribute and if that closure doesn’t contain all attributes of the relation add next attribute and find the closure again. Repeat the step till you get all attributes in closure of attributes.

Note: To quickly find a candidate key and save time, the attribute which is not present on the right side of the FD’s in the relation will always going to be a part of candidate key.

Step 1: Find Closure of AB

AB+ = AB->ABCD->ABCDE

So as you can see all the attributes are present in AB which makes AB a candidate key. You have to keep in mind that there can be many candidate keys and you must find all of them.

Step 2: Find Closure of D

D+ = D->DA

So the closure of D doesn’t contain all the attributes which makes it not suitable for candidate key. Now we must append other attribute to D to try further. Since DA can’t determine any more attribute we append D with B

Step 3: Find Closure of DB

DB+ = DB->DBA->DBAC->DBACE

All the attributes are present so DB is also a candidate key in Database Relation R.

Similarly you must try to find out all the candidates keys that are present in the example used in this tutorial.

I hope you get to understand the importance of and How to Find Candidate Key in Database Relation R and your work is to find all the keys and comment below the answer.

Leave a Reply