SQL Alternate key with Example

aimtocode

Alternate Key

All the keys which are not primary key are called an alternate key. It is a candidate key which is currently not the primary key. However, A table may have single or multiple choices for the primary key.

Lets take an example to understand the alternate key concept. Here we have a table Employee, this table has three attributes: Emp_Id, Emp_Number & Emp_Name.

emp_Id Emp_Number Emp_Name
E01 1214 Prayag
E22 2272 Pankaj
E23 3261 Rakesh
E44 4825 Hazra

There are two candidate keys in the above table:

								
 {emp_Id}	
    and
 {Emp_Number}   

DBA (Database administrator) can choose any of the above key as primary key. Lets say Emp_Id is chosen as primary key.

Since we have selected Emp_Id as primary key, the remaining key Emp_Number would be called alternative or secondary key.

Read Also:


aimtocode