Tuesday, August 18, 2009

Difference between Superkey, Candidate Key and Primary Key

A superkey is defined as a set of attributes of a relation for which it holds that in all relations assigned to that variable there are no two distinct tuples (rows) that have the same values for the attributes in this set.As an example
Code:
+---------------+----------------+--------------+
Roll Number First Name Last Name
+--------------+----------------+--------------+
CSU0001 Shabbir Bhimani
CSU0002 SomeName SurName
CSU0003 Larry page
+---------------+---------------+---------------+
Now here we have the following as super keys1. Roll Number First Name2. Roll Number First Name Last Name Now in plain language.
Any Unique key with some Non Unique key combination is called a super key of the relationship. A candidate key of a relationship is a set of attributes of that relationship such that there are no two distinct tuples with the same values for these attributes. In simple example candidate key is a minimal superkey, i.e. a superkey of which no proper subset is also a superkey.Since a relation is a set(no duplicate elements), it holds that every relation will have at least one candidate key (because the entire heading is always a superkey). For practical reasons RDBMSs usually require that for each relation one of its candidate keys is declared as the primary key

3 comments: