What is primary key?
Answer:
Primary key is a set of one or more attributes which can uniquely identify each tuple of a relation.
Example:
Employee_id |
Employee_name |
Department |
101 |
Ravi Kumar |
Sales |
102 |
Tarun A |
IT |
103 |
Jennifer Davis |
HR |
104 |
Martin Woods |
HR |
105 |
Ron Romy |
IT |
In the Employee table, the Employee_id of all employees are different . So it can be used to uniquely identify each employee and hence, we set Employee_id as the primary key.
Additional points:
- A relation can have only 1 primary key.
- A primary key can consist of single or multiple columns.
- Primary keys must contain unique values.
- Primary keys cannot contain NULL values.