Header Ads

SQL KEYS

Primary key - An attribute(column)or set of attribute(set of column)that is unique in every row is called Primary key. in other words we can say any column or set(combination of two or more column)which can uniquly identify the records of each row is called as primary key

for Example

In student table there may be Rollno column, name column, address column, marks column etc. In these column there may be same name of two or more sudent, and marks also can be same of two or more students but the Rollno of student cannot be same of two students in same class so here Rollno can be Primary key.

Candidate Key - Candidate key is a key which are lible to be a primary key but it is not a primary key is called candidate key. In simple word Any column or set of column that can uniquely identify the records of each row that column is candidate for primary key. such column is called candidate key

For Example
in the same student table the cobination of Rollno and student name column can uniquely identify each rows because the Rollno and name cannot be same to other student so here the Combination of Rollno and student name can also be Primary key but we have taken Rollno as primary key so here Rollno and student name is candidate key.

Alternate Key - Any column or set of column that is candidate for the Primary key but is not the Primary key is called the Alternate key

For Example

In the same student table the Combination of Rollno and student name are Alternate key

Composite Key -- When we make Primary key by combining two column the is called composite key.

For Example

In the student table when we make Primary key by combining Rollno and student name column then this type of key is called Composite Key



Note:

Every Primary key is a candidate key but Every candidate is not Primary key

No comments:



Powered by Blogger.