Composite key

Another type of key is called a composite key, which is a combination of two or more attributes in a table that can be used to uniquely identify each row in the table.

Example

PRODUCT (NProd, nom_prod, prixUHT)

NProd → nom_prod

NProd → priceUHT

Then NProd is a key

Example

Employee {ID, First_name, Last_name, Salary, Age, Address}

We have two candidate keys (ID) and (First_name, Last_name)

Because they uniquely identify each employee in the EMPLOYEE relationship. Here, we'll choose ID as the primary key, because sometimes it can happen that two employees have the same first and last name, so it will be easy to find an employee with his ID.