0% found this document useful (0 votes)
19 views5 pages

Types of Key:: For Example

Keys play an important role in relational databases by uniquely identifying records. There are several types of keys: 1. A primary key uniquely identifies each record in a table, such as an employee ID. 2. A candidate key can also uniquely identify records, like a social security number, but only one can be the primary key. 3. A super key contains attributes that uniquely identify records plus other attributes, making it a superset of candidate keys. 4. A foreign key in one table matches the primary key in another table to link the tables, such as an employee table linking to a department table by the department ID.

Uploaded by

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

Types of Key:: For Example

Keys play an important role in relational databases by uniquely identifying records. There are several types of keys: 1. A primary key uniquely identifies each record in a table, such as an employee ID. 2. A candidate key can also uniquely identify records, like a social security number, but only one can be the primary key. 3. A super key contains attributes that uniquely identify records plus other attributes, making it a superset of candidate keys. 4. A foreign key in one table matches the primary key in another table to link the tables, such as an employee table linking to a department table by the department ID.

Uploaded by

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

Keys

o Keys play an important role in relational database.


o It is used for 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:
1. Primary key
o It is the first key which is used to uniquely identify one and only one instance of an
entity. 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.
o In the EMPLOYEE table, ID can be primary key since it is unique for each employee.
In EMPLOYEE table, we can even select License_Number and Passport_Number as
primary key since they are also unique.
o For each entity, selection of primary key is based on requirement and developers.
2. Candidate key
o Candidate key is an attribute or set of attribute which can uniquely identify a tuple.
o The remaining attributes except primary key which is as strong as primary key are
considered as candidate key.

For example: In the EMPLOYEE table, id is best suited for primary key. Rest of the
attributes like: SSN, Passport_Number and License_Number etc. are considered as
candidate key.
3. Super Key
Super key is a set of attribute which can uniquely identify a tuple. Super key is a superset of
candidate key.

For example: In the above EMPLOYEE table, for(EMPLOEE_ID, EMPLOYEE_NAME) the name
of two employees can be same but their EMPLYEE_ID can't be same. Hence, this
combination can also be a key.

The super key would be: EMPLOYEE-ID, (EMPLOYEE_ID, EMPLOYEE-NAME) etc.

4. Foreign key
o Foreign keys are the column of table which is used to point to the primary key of
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 primary key of 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.

You might also like