Candidate Key Vs Primary Key Vs Alternate key Vs Composite Key Vs Unique Key VsForeign Key

Monday, 6 May 2013

Candidate Key Vs Primary Key Vs Alternate key Vs Composite Key Vs Unique Key VsForeign Key


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 Student Table RollNo and EnrollNo are Candidate Keys since  these 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  RollNo and EnrollNo, RollNo becomes Alternate Keys when we define EnrollNo 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.

Foreign Key


Foreign Key is a field in table that is Primary key in another table. It can accept multiple null, duplicate values. Example : We can have a Emp_Id column in the Employee table which is pointing to Emp_Id column in a department table where it a foreign key.

No comments:

Post a comment