A candidate key is a super key but vice versa is not true. Primary Key: There can be more than one candidate key in a relation out of which one can be chosen as primary key. For Example, STUDNO as well as STUDPHONE both are candidate keys for relation STUDENT but STUDNO can be chosen as primary key (only one out of many candidate keys). Check here: DB Basics - What are Candidate, Primary, Composite & Super Keys and Difference between them? I'll take example of an Employee table: Employee ( Employee ID, FullName, SSN, DeptID ) 1. Candidate Key: are individual colu.
What is difference between Primary Key, Unique Key and candidate key?
skaffman349k8888 gold badges745745 silver badges730730 bronze badges
RamRam5,7751414 gold badges5151 silver badges8383 bronze badges
7 Answers
![Key Key](http://cdncontribute.geeksforgeeks.org/wp-content/uploads/image7.png)
Candidate key is a minimal (i.e. irreducible) key, unique key is a pleonasm, and primary key is an obsoleted concept still surviving from the days when people thought it possible for one key to be 'more unique' than any of the others.
Erwin SmoutErwin Smout15.8k44 gold badges2222 silver badges4949 bronze badges
Super Key is the set of one or more column (ie attributes) which uniquely identifies a record.
Candidate key is a minimal Super key.(it mean we cant remove any attributes from it otherwise it will not remain Superkey anymore).
Primary Key is a arbitrary selected Candidate key. There must be only and only One primary key. We can choose any candidate key as a Primary key.Other candidate keys which are not chosen as Primary are called Alternate Keys.
If Primary Key have more then one column (or attributes) ,it is called Composite Key.
saurabh kimothisaurabh kimothi
Candidate keys - It is a column that can uniquely identify all columns for a specific row or instance of your database table. Your passport ID is a good example of a Candidate key and when using this ID you can retrieve a persons name, surname and other details related to that specific person.
Primary key - There may be a few Candidate keys on a specific database table which is unique and can be used to identify a specific instance in a table e.g. Vehicle registration number, Chassis number, engine serial number etc... but remember there can only be one candidate key that will be used as a primary key. Difference between Candidate Key vs Primary Key:-) Both Primary and Candidate keys can uniquely identify records in a table on database.
2) Both Primary and Candidate keys are has constraints UNIQUE and NOT NULL.
3) Primary key or Candidate keys can be either single column or combination of multiple columns in a table.
Arunashis PaulArunashis Paul
Google does not work anymore?
Alex ReitbortAlex Reitbort12.1k11 gold badge3131 silver badges6060 bronze badges
Candidate Key – A Candidate Key can be any column or a combination of columns that can qualify as unique key in database. There can be multiple Candidate Keys in one table. Each Candidate Key can qualify as Primary Key.
Primary Key – A Primary Key is a column or a combination of columns that uniquely identify a record. Only one Candidate Key can be Primary Key.One needs to be very careful in selecting the Primary Key as an incorrect selection can adversely impact the database architect and future normalization. For a Candidate Key to qualify as a Primary Key, it should be Non-NULL and unique in any domain. I have observed quite often that Primary Keys are seldom changed. I would like to have your feedback on not changing a Primary Key.
gngolakiagngolakia
A composite key is a primary key which has more than 1 column. For example consider the many to many relation between student and courses. Here we need another table , lets say studentcourses.
This studentcourses table will have student_id and course_id as its columns. This will form your composite key.
Candidate key is a set of columns which can uniquely identify the values in a table and can act as a unique key. One of these candidate keys will become the primary key and the rest will become alternate keys.
Unique key as the name suggests , is used to uniquely identify a value in a table. For example Emp_id etc. Every candidate key will act as a unique key. Unique key can never be a
LiyaliNULL
value. 4,92111 gold badge2020 silver badges3939 bronze badges
user1212user121240133 gold badges1010 silver badges2222 bronze badges
Since all the answers are missing physical representation and some of them are incomplete. So here is the difference by graphical representation
Super Key
Super key is a set of one or more than one keys that can be used to identify a record uniquely in a table.
Example : Primary key, Unique key, Alternate key are subset of Super Keys.
Candidate Key
A Candidate Key is a set of one or more fields/columns that can identify a record uniquely in a table. There can be multiple Candidate Keys in one table. Each Candidate Key can work as Primary Key.
Example: In above diagram
ID
, RollNo
and EnrollNo
are Candidate Keys since all these three fields can be work as Primary Key.Primary Key
Primary key is a set of one or more fields/columns of a table that uniquely identify a record in database table. It can not accept null, duplicate values. Only one Candidate Key can be Primary Key.
Alternate key
A Alternate key is a key that can be work as a primary key. Basically it is a candidate key that currently is not primary key.
Example: In above diagram
RollNo
and EnrollNo
becomes Alternate Keys when we define ID
as Primary Key.Composite/Compound Key
Composite Key is a combination of more than one fields/columns of a table. It can be a Candidate key, Primary key.
Unique Key
Uniquekey is a set of one or more fields/columns of a table that uniquely identify a record in database table. It is like Primary key but it can accept only one null value and it can not have duplicate values. For more help refer the article Difference between primary key and unique key.
Foreign Key
Foreign Key is a field in database table that is Primary key in another table. It can accept multiple null, duplicate values. For more help refer the article Difference between primary key and foreign key.
Example : We can have a
ManozManozDeptID
column in the Employee table which is pointing to DeptID
column in a department table where it a primary key.4,4441010 gold badges4444 silver badges9393 bronze badges