Loading, please wait...

Keys in database

Keys-: Identify the row with unique column name is known as keys. It plays an important role in relational database. It is used for identifying unique rows from table. It also establishes relationship among tables.

 

Various keys are

  • Primary key
  • Candidate key
  • Foreign key
  • Super key
  • Alternate key
  • Composite key

Primary key-: A primary key is a candidate key that is the main key for any table. It is a key that can uniquely identify each record in a table. Null values are not permitted in the primary key.

 

 

For this table we can make the Student_id column as the primary key.

Candidate key-: A candidate is a subset of a super key. Any attribute that uniquely identifies in a table is a candidate for the primary key such an attribute is called candidate key. Every table must have at least one candidate key but at the same time can have a lot. A super key with no unnecessary attribute is known as candidate key.  

 

 


 

 

 

                          

For this table we can make the Student_id, First Name, Last Name column as the candidate key

 

Foreign key-: A foreign key is mainly a primary key from one table that appears as a field in another where the first table has a relationship to the second.

 For example if we had a table A with a primary key Course_id that linked to a table B where Course_id was a field in table B, then Course_id would be a foreign key in B.

 

 

 

Super key-: Super Key is a superset of Candidate key. A Super key is the set of fields within a table that uniquely identifies each record within that table.

 

 

Alternate key-: It is also known as secondary key. Those key which are not selected as primary key are known as secondary keys or alternative keys.

 

There are two types of alternate key

  • Non-key Attributes
  • Non-prime Attributes

 

 

Composite key-: It is the key that consists of more than one attribute to uniquely identify rows (also known as records & tuples) in a table is called composite key.