Click here to Skip to main content
15,888,133 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
What is the difference between the terms primary key, super key and candidate key used in Database Management System - DBMS.

I did google but couldn't distinguish them. The terms candidate key and primary key appear to be the same.
Posted
Updated 4-Nov-17 14:57pm

Super Key: An attribute or set of attributes that uniquely identifies a tuple within a relation

Candidate key: A super key such that no proper subset is a super key within the relation

Primary key: The candidate key that is selected to identify tuples uniquely within the relation, the candidate keys which are not selected as PKs are called "Alternate keys"
 
Share this answer
 
Comments
ridoy 1-Nov-12 15:42pm    
exactly..+5
Super Keys : Super key stands for superset of a key.
A Super Key is a set of one or more attributes that are taken collectively and can identify all other attributes uniquely.


Candidate Keys
Candidate Keys are super keys for which no proper subset is a super key. In other words candidate keys are minimal super keys.
<br />
Primary Key:

It is a candidate key that is chosen by the database designer to identify entities with in an entity set. Primary key is the minimal super keys. In the ER diagram primary key is represented by underlining the primary key attribute. Ideally a primary key is composed of only a single attribute. But it is possible to have a primary key composed of more than one attribute.

Composite Key
Composite key consists of more than one attributes.

Example: Consider a Relation or Table R1. Let A,B,C,D,E are the attributes of this relation.

R(A,B,C,D,E)
A→BCDE This means the attribute 'A' uniquely determines the other attributes B,C,D,E.
BC→ADE This means the attributes 'BC' jointly determines all the other attributes A,D,E in the relation.

Primary Key :A
Candidate Keys :A, BC
Super Keys : A,BC,ABC,AD

ABC,AD are not Candidate Keys since both are not minimal super keys.
 
Share this answer
 
v2
Comments
sumitkrishna2002 11-Jun-15 23:30pm    
good explaination
Member 12923909 5-Jan-17 16:19pm    
You haven't defined "key". How are we supposed to know what it means for a super key to be a superset of a key if we don't know what a key is?
Check this blog[^] Video[^]

I'll take example of an Employee table:
Employee (
Employee ID,
FullName,
SSN,
DeptID
)

1. Candidate Key: are individual columns in a table that qualifies for uniqueness of all the rows. Here in Employee table EmployeeID & SSN are Candidate keys.

2. Primary Key: is the columns you choose to maintain uniqueness in a table. Here in Employee table you can choose either EmployeeID or SSN columns, EmployeeID is preferable choice, as SSN is a secure value.

3. Alternate Key: Candidate column other the Primary column, like if EmployeeID is PK then SSN would be the Alternate key.

4. Super Key: If you add any other column/attribute to a Primary Key then it become a super key, like EmployeeID + FullName is a Super Key.

5. Composite Key: If a table do have a single columns that qualifies for a Candidate key, then you have to select 2 or more columns to make a row unique. Like if there is no EmployeeID or SSN columns, then you can make FullName + DateOfBirth as Composite primary Key. But still there can be a narrow chance of duplicate row.
 
Share this answer
 
v3
Comments
Dave Kreskowiak 15-Sep-15 9:34am    
Why are you adding solutions to 3 year old questions? Your answer doesn't add anything to the discussion that hasn't already been said.
manub22 15-Sep-15 9:38am    
I believe its an open forum, be it 3-4 years old, I don't care, as far as I'm helping SQL community and getting myself benefited from it. Let it trend down if its not useful, otherwise let it trend it up. What's your problem?
Dave Kreskowiak 15-Sep-15 9:44am    
Because every post to a QA question pushes it to the top of the question list where other people post additional clarifying questions for the original poster and don't notice that they're never going to get answers to them.

Like I said, you're not adding anything to the discussion at hasn't already been said.

manub22 15-Sep-15 9:53am    
Oh, B.T.W thanks for down-voting my answer, I just checked it!
Dave Kreskowiak 15-Sep-15 10:23am    
Yep and I already told you why.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900