what is candidate key in dbms
A candidate key in DBMS is a minimal set of attributes (columns) that uniquely identifies each row (tuple) in a table , and from which the primary key is chosen.
Quick Scoop: Simple Definition
- A candidate key is any column or combination of columns that can uniquely identify every record in a table.
- It must be unique (no two rows share the same candidate key value) and minimal (if you remove any attribute from it, it stops being unique).
- A table can have multiple candidate keys, but only one of them is picked as the primary key.
Think of a class attendance sheet: Roll_No and Email might both uniquely identify a student. Both are candidate keys, but you choose only one as the primary key.
Key Properties (What makes a candidate key)
- Uniqueness
- Every row must have a different value for the candidate key.
* Example: In an `Employees` table, `EmployeeID` or `Email` can both be unique per employee.
- Minimality
- You cannot remove any attribute from the candidate key and still uniquely identify rows.
* If `{A, B}` is a candidate key, then neither `A` alone nor `B` alone should uniquely identify the row.
- Subset of Super Key
- A candidate key is a minimal super key : it is a super key with no extra, redundant attributes.
Small Story-Style Example
Imagine a table Students:
Roll_No| ID| Name| Email
---|---|---|---
101| S01| Aayush| a@uni.edu
102| S02| Neha| n@uni.edu
103| S03| Ravi| r@uni.edu
- Possible super keys could be:
{Roll_No},{ID},{Email},{Roll_No, ID},{Roll_No, Email},{ID, Email}, etc.
- The candidate keys are the minimal super keys:
{Roll_No},{ID},{Email}(each alone uniquely identifies a row).
- From these, you pick one (say
Roll_No) as the primary key , butIDandEmailare still candidate keys.
How candidate key differs from other keys
Here is a quick comparison to avoid confusion:
html
<table>
<tr>
<th>Key Type</th>
<th>What it is</th>
</tr>
<tr>
<td>Super key</td>
<td>Any set of attributes that can uniquely identify a row (may contain extra attributes).</td>
</tr>
<tr>
<td>Candidate key</td>
<td>Minimal super key with no redundant attributes; table can have many of these.</td>
</tr>
<tr>
<td>Primary key</td>
<td>One candidate key chosen by the designer as the main unique identifier.</td>
</tr>
<tr>
<td>Alternate key</td>
<td>Other candidate keys that were not chosen as primary key.</td>
</tr>
</table>
All these definitions follow the standard relational model description where a candidate key is a minimal super key.
Why candidate keys matter (exam / interview POV)
- They ensure data integrity by preventing duplicate rows.
- They are the basis for normalization , helping to remove redundancy and anomalies.
- They help classify attributes into prime (in some candidate key) and non-prime , which is used in higher normal forms like BCNF, 3NF, etc.
TL;DR:
A candidate key in DBMS is a minimal set of attributes that uniquely
identifies each record , there can be multiple such keys per table, and the
primary key is simply one selected candidate key.
Bottom note: Information gathered from public forums or data available on the internet and portrayed here.