Difference between Super Key and Candidate Key
Last Updated: 23-02-2021
Super Key:
Super Key is an attribute (or set of attributes) that is used to uniquely
identifies all attributes in a relation. All super keys can’t be candidate keys but its reverse is true. In relation, the number of super keys is more than the number of candidate keys.
Example:
We have a given relation R(A, B, C, D, E, F) and we shall check for being super keys by following given dependencies:
Super Key is an attribute (or set of attributes) that is used to uniquely
identifies all attributes in a relation. All super keys can’t be candidate keys but its reverse is true. In relation, the number of super keys is more than the number of candidate keys.
Example:
We have a given relation R(A, B, C, D, E, F) and we shall check for being super keys by following given dependencies:
Functional dependencies Super key
AB->CDEF YES
CD->ABEF YES
CB->DF NO
D-.BC NO
By Using key AB we can identify the rest of the attributes (CDEF)of the table. Similarly Key CD. But, by using key CB we can only identify D and F, not A and E. Similarly key D.
Candidate Key:
Candidate key is a set of attributes (or attribute) which uniquely identify the tuples in a relation or table. As we know that Primary key is a minimal super key, so there is one and only one primary key in any relation but there is more than one candidate key can take place. Candidate key’s attributes can contain a NULL value which opposes to the primary key.
Example:
Student{ID, First_name, Last_name, Age, Sex, Phone_no}
Here we can see the two candidate keys ID and {First_name, Last_name, DOB, Phone_no}. So here, there are present more than one candidate keys, which can uniquely identify a tuple in a relation.
Example:
Student{ID, First_name, Last_name, Age, Sex, Phone_no}
Here we can see the two candidate keys ID and {First_name, Last_name, DOB, Phone_no}. So here, there are present more than one candidate keys, which can uniquely identify a tuple in a relation.
Difference between Primary key and Unique key
Primary key
A primary key is a column of a table that uniquely identifies each tuple (row) in that table. The primary key enforces integrity constraints to the table. Only one primary key is allowed to use in a table. The primary key does not accept the any duplicate and NULL values. The primary key value in a table changes very rarely so it is chosen with care where the changes can occur in a seldom manner. A primary key of one table can be referenced by foreign key of another table.
For a better understanding of the primary key, we take a table named as Student table, having attributes such as Roll_number, Name, Batch, Phone_number, Citizen_ID.
The roll number attribute can never have identical and NULL value because every student enrolled in a university can have a unique Roll_number, therefore two students cannot have the same Roll_number and each row in a table is uniquely identified with the student’s roll number. So, we can makeRoll_number attribute as a primary key in this case.
Unique key
Unique key constraints also identify an individual tuple uniquely in relation or table. A table can have more than one unique key, unlike a primary key. Unique key constraints can accept only one NULL value for the column.
Unique constraints are also referenced by the foreign key of another table. It can be used when someone wants to enforce unique constraints on a column and a group of columns which is not a primary key.
Comments
Post a Comment
Please, do not enter any spam link in the comment box.