SQL Keys Most Useful Types Of Keys In SQL

What is KEY in SQL?

A key in SQL is an attribute or a set of attribute which helps you uniquely identify a record or a row of data in a relation/ table.

Primary Key:

A Primary key is a table attribute or column that identify every record present in a table uniquely.

There can be only one primary key attribute in a table and primary key column elements can’t be same or Null values.

Roll No. is the Primary Key in the above table.

Super Key:

It is the set of all columns which help to identify rows in a table uniquely.

Candidate Key:

A candidate key is a column or a set of columns that can qualify as a primary key in the database. There can be multiple candidate keys in a table and only one candidate key can qualify as the primary key.

Composite Key:

It is a set of two or more attributes that helps to identify each tuple in a table uniquely. Any key such as super, primary, or candidate key etc. can be called composite key if it has more than one attribute.

Foreign Key:

A foreign key is a key used to link two tables together. This is sometimes also called a referencing key.

Leave a Reply

Your email address will not be published. Required fields are marked *