0% found this document useful (0 votes)
162 views

1DBMS Keys - Primary, Foreign, Candidate and Super Key - Javatpoint PDF

This document defines and describes different types of keys used in relational databases: primary keys, foreign keys, candidate keys, and super keys. It provides examples of each using tables like Employees and Departments. Primary keys uniquely identify records, foreign keys link tables based on another table's primary key, candidate keys could also uniquely identify records, and super keys may include additional attributes to uniquely identify records.

Uploaded by

riddhi chavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
162 views

1DBMS Keys - Primary, Foreign, Candidate and Super Key - Javatpoint PDF

This document defines and describes different types of keys used in relational databases: primary keys, foreign keys, candidate keys, and super keys. It provides examples of each using tables like Employees and Departments. Primary keys uniquely identify records, foreign keys link tables based on another table's primary key, candidate keys could also uniquely identify records, and super keys may include additional attributes to uniquely identify records.

Uploaded by

riddhi chavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

12/17/2020 DBMS Keys: Primary, Foreign, Candidate and Super Key - javatpoint

ADVERTISEMENT BY ADRECOVER

Keys
Keys play an important role in the relational database.

It is used to uniquely identify any record or row of data from the


table. It is also used to establish and identify relationships
between tables.

For example: In Student table, ID is used as a key because it is unique


for each student. In PERSON table, passport_number, license_number,
SSN are keys since they are unique for each person.

Types of key:

https://www.javatpoint.com/dbms-keys 1/8
12/17/2020 DBMS Keys: Primary, Foreign, Candidate and Super Key - javatpoint

1. Primary key

It is the first key which is used to identify one and only one
instance of an entity uniquely. An entity can contain multiple keys
as we saw in PERSON table. The key which is most suitable from
those lists become a primary key.

In the EMPLOYEE table, ID can be primary key since it is unique


for each employee. In the EMPLOYEE table, we can even select
License_Number and Passport_Number as primary key since they
are also unique.

For each entity, selection of the primary key is based on


requirement and developers.

https://www.javatpoint.com/dbms-keys 2/8
12/17/2020 DBMS Keys: Primary, Foreign, Candidate and Super Key - javatpoint

2. Candidate key

A candidate key is an attribute or set of an attribute which can


uniquely identify a tuple.

The remaining attributes except for primary key are considered as


a candidate key. The candidate keys are as strong as the primary
key.

For example: In the EMPLOYEE table, id is best suited for the primary
key. Rest of the attributes like SSN, Passport_Number, and
License_Number, etc. are considered as a candidate key.

3. Super Key

Super key is a set of an attribute which can uniquely identify a tuple.


Super key is a superset of a candidate key.

For example: In the above EMPLOYEE table, for(EMPLOEE_ID,


EMPLOYEE_NAME) the name of two employees can be the same, but
their EMPLYEE_ID can't be the same. Hence, this combination can also
be a key.

The super key would be EMPLOYEE-ID, (EMPLOYEE_ID, EMPLOYEE-


NAME), etc.

4. Foreign key ⇧

https://www.javatpoint.com/dbms-keys 3/8
12/17/2020 DBMS Keys: Primary, Foreign, Candidate and Super Key - javatpoint

Foreign keys are the column of the table which is used to point to
the primary key of another table.

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.

We add the primary key of the DEPARTMENT table,


Department_Id as a new attribute in the EMPLOYEE table.

Now in the EMPLOYEE table, Department_Id is the foreign key,


and both the tables are related.

← prev next →
ADVERTISEMENT BY ADRECOVER

https://www.javatpoint.com/dbms-keys 4/8

You might also like