Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: DBMS
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 1-Nov-12 8:49am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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"
  Permalink  
Comments
ridoy at 1-Nov-12 15:42pm
   
exactly..+5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.

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.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

A superkey is basically all sets of columns for which no two rows share the same values for those sets.
 
A table can have multiple superkeys of course, and minimal superkey is considered a candidate key.
 
Read here for a good source of info on superkeys:
 
Superkey example
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 540
1 Sergey Alexandrovich Kryukov 426
2 Yogesh Kumar Tyagi 384
3 Prakriti Goyal 280
4 Maciej Los 205
0 OriginalGriff 6,472
1 Sergey Alexandrovich Kryukov 5,404
2 Maciej Los 3,434
3 Peter Leow 3,259
4 DamithSL 2,495


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 9 Sep 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100