Page 455 - Computer_Science_F5
P. 455
Computer Science (f) Candidate key of another table, creating a relationship between
them. It uses values from the referenced table to
A candidate key, denoted as K,
restrict the domain of attributes in the referencing
is a minimal set of attributes
table, maintaining data integrity and enabling
that uniquely identify a
navigation between different entities. For
row in a table. Each set of
FOR ONLINE READING ONLY
attributes has unique values
works in a specific department. Instead of storing
per row, and removing any example, in an Employee database, each employee
attribute can cause duplicate department information in the employee table, we
rows. Unlike the primary key, link the two tables by adding the primary key of
which uniquely identifies a the DEPARTMENT table, Department_ID, as a
record with only one key per foreign key in the EMPLOYEE table, establishing
table, a candidate key can the relationship as shown in Figure 8.10.
have multiple keys per table.
For example, in Figure 8.9, EMPLOYEE DEPARTMENT
the columns StudID, Roll_ Employee_ID Department_ID
Number, and email can all be Employee_Name Department_Name
candidate keys as they contain Passport_Number
unique values and can be used License_Number
to identify data. Any of these SSN
can be chosen as the primary Department_ID
key. Figure 8.10: Example of the foreign key using an
employee database
(g) Alternate key
The candidate keys that are (i) Composite Key
not selected as the primary key A composite key in relational databases is a
are called alternate keys. In combination of two or more columns that uniquely
this kind of key, columns have identify each row in a table. Uniqueness is
a candidate key except for the guaranteed only when the columns are combined,
primary key, which has an not individually. Composite keys are a type of
alternate key. For example, in candidate key formed by multiple columns. Note
Figure 8.9, the columns - Roll_ that a composite key can be made from multiple
No and Email are alternate candidate keys and cannot be empty or null.
keys, considering that Student
ID is the primary key. Activity 8.3:
(h) Foreign key Identify keys in the tables
A foreign key is an attribute Aim:
or set of attributes in one table Identify and understand the different types of
that matches the primary key keys (such as Primary, Foreign, Candidate,
446
for Advanced Secondary Schools
Computer Science Form 5.indd 446 23/07/2024 12:34

