Candidate Key in DBMS
What is a Primary Key?
Candidate keys are selected from the set of super keys, the only thing that you should remember while selecting candidate keys is, it should not have any redundant attitude.
In this article , we will learn about Candidate Key in DBMS.
A candidate satisfies the following properties
- A candidate key column must be unique i.e all the columns that are involved in the candidate key also must be unique
- A candidate key may have more than one attribute
- A candidate key column will not contain any null value
- Candidate key always selects a minimum column combination that helps to uniquely identify the record.
Example for Candidate Key
Consider the following table student
ID | NAME | PHONE |
---|---|---|
66 | Elena | 9789578575 |
67 | Haley | 8758273875 |
68 | Alex | 7847326558 |
69 | Elena | 7923857563 |
First, identify all the super keys present in the table, then eliminate the super keys that contain a column with duplicate data. Then the remaining superkeys that are left or nothing but candidate keys
- {Id}: ID column will contain all unique values hence ID column is a candidate key
- {phone}: As no two students have the same phone number, it is not a redundant data column and hence phone column is a candidate key
- {Id, phone}: As both ID and phone are unique for all students this combination is a valid candidate key
- {Id, Name}: This combination is not a candidate key because the name column may have duplicate values
- {Id, phone, Name}: This combination is not a candidate key because the name column may have duplicate values
- {Name, Phone}: This combination is not a candidate key because the name column may have duplicate values
Candidate keys available in the table student
- {Id}
- {phone}
- {Id, phone}
Candidate key versus super key
- First of all, you need to understand that all candidate keys are super keys this is because candidate keys are selected from super keys
- Look for those keys from which we can remove any columns that contain duplicate data. In the above example, we have not chosen {Id, name} as candidate key because {Id} alone can identify a unique row in the table, and {Name} column is redundant.
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment