Keys


☞ A key allow us to identify an attribute or a set of attributes on the basis of which a table is identified.

☞ They are used to establish and identify relation among two or more tables.

☞ They also ensure that each record within a table can be uniquely identified by combination of one or more fields within a table.

☞ The different types of keys in an RDBMS are as follows :

1. Primary Key
2. Candidate Key
3. Alternate Key
4. Foreign Key
5. Composite Key

Primary Key

☞ It uniquely identifies a tuple/record in a table.

☞ It cannot be left null.

☞ One table can have only one primary key.


Candidate Key

☞ All those attributes/fields that are capable of becoming a primary key are known as candidate key.


Alternate Key

☞ A candidate key that is not the primary key is called an alternate key.

☞ Alternate key = Candidate keys - Primary key


Foreign Key

☞ It is a non-key attribute whose value is derived from the primary key of another table.


Composite Key

☞ If in a table we use more than one field to identify records, it is known as composite key.