/    /  DBMS – Keys

Keys In DBMS

 

What are keys?

A set of attributes of a relation, where the values of that set of attributes allow us to uniquely identify a single tuple.

 

There are 5 different kinds of Keys: 

  •  Super Key : It is a set of one or more attributes in a relation used to uniquely identify a tuple.

Ex :  S-No, S-Name

  • Candidate Key : A Super Key may contain irrelevant attributes. A super key without irrelevant attributes is called a ‘Candidate Key’.

Ex :  S-No

Candidate Key is a Minimal Super Key

  •  Primary Key : The term ‘Primary Key’ can be used to denote a candidate key that is chosen by the database designer as the principal means, identifying tuples within a relation.

 Ex :   S-No

  • Secondary Key : Any key other than the primary key is called a ‘Secondary Key’.

Ex :   S-Name

  •  Foreign Key : Suppose there are two relations R1 and R2.

Let’s say some of the attributes are common between these two relations. Let K1 be the Primary Key in R1. Let K2 be the Primary Key in R2.

If K2 is also present in R1, it is said to be the ‘Foreign Key’ in R1 because it is the primary key in R2.

 

Let’s take an example:

R1: Student

S-NoS-NameD-No
241Alex14
267Max14
283Maggie15
292Ben15
304Trex16

 

R2 : Department

D-NoD-name
14CSE
15IT
15IT
16EEE
17AI

 

Here,  D-No in R1 is said to be ‘Foreign Key’ because D-No in R2 is the Primary Key.

 

Reference :

Keys In DBMS.