Keys in DBMS
Keys in DBMS
Keys in DBMS-
A key is a set of attributes that can identify each tuple uniquely in the given relation.
1. Super Key-
A super key is a set of attributes that can identify each tuple uniquely in the given relation.
A super key is not restricted to have any specific number of attributes.
Thus, a super key may consist of any number of attributes.
Example-
Given below are the examples of super keys since each set can uniquely identify each
student in the Student table-
( roll , name , age , address , class , section )
( class , section , roll )
(class , section , roll , mob)
( name , address )
NOTE-
All the attributes in a super key are definitely sufficient to identify each tuple uniquely in the
given relation but all of them may not be necessary.
2. Candidate Key-
Example-
Given below are the examples of candidate keys since each set consists of minimal
attributes required to identify each student uniquely in the Student table-
(roll )
(Mob)
( name , address )
NOTES-
All the attributes in a candidate key are sufficient as well as necessary to identify each
tuple uniquely.
Removing any attribute from the candidate key fails in identifying each tuple uniquely.
The value of candidate key must always be unique.
The value of candidate key can never be NULL.
It is possible to have multiple candidate keys in a relation.
Those attributes which appears in some candidate key are called as prime attributes.
3. Primary Key-
A primary key is a candidate key that the database designer selects while designing the
database.
OR
Candidate key that the database designer implements is called as a primary key.
NOTES-
Remember-
4. Alternate Key-
Candidate keys that are left unimplemented or unused after implementing the primary key
are called as alternate keys.
OR
Unimplemented candidate keys are called as alternate keys.
5. Foreign Key-
o another table.
o In a company, every employee works in a specific department, and employee and
department are two different entities. So we can't store the information of the department
in the employee table. That's why we link these two tables through the primary key of
one table.
o We add the primary key of the DEPARTMENT table, Department_Id as a new attribute
in the EMPLOYEE table.
o Now in the EMPLOYEE table, Department_Id is the foreign key, and both the tables are
related.
o Foreign keys are the column of the table which is used to point to the primary key of