DEV Community

Cover image for Importance of Keys in DBMS
hebaShakeel
hebaShakeel

Posted on

Importance of Keys in DBMS

DBMS Keys
It is used to identify unique records by the combination of one or more fields(attributes) in the database table.
Keys play an important role in DBMS.

Different Types of Keys:

i) Candidate Keys - It is a minimal(minimum) set of attributes that can identify each tuple/row uniquely in a Relation.

Example - In the below example of Employee relation, we can see that EPhone is the only unique attribute. Hence it can be treated as a Candidate Key.
Alt Text

ii) Primary Keys - It is a set of one or more attributes that can uniquely identify each tuple.
-> Primary Key cannot have "NULL" values.
-> Only one Primary Key is possible in a table.
-> Values of Primary Key are unique and they cannot be repeated.
-> One of the Candidate Keys is selected as the Primary Key.

iii) Super Keys - It is a superset of Candidate Keys.

-> Trivial Super Key - It is the set of all attributes.

iv) Foreign Keys - An attribute which is a key in one table and it also behaves as a Primary Key in another table is known as Foreign Key.
-> It is used to combine two tables logically.

v) Alternate Key - All other Candidate Keys which are not selected as a Primary Key is called as Alternate Keys. It is also called as Secondary Key.

vi) Composite Keys - If a key contains more than one attribute then it is called as a Composite Key.

Example: Employee table has key=>{eName, eAge, eAddress}. This key will be called as Composite Key.

Thank You!
See you soon.

Discussion (0)