Database Basics
In an employee table (emp_no, email, name, dept), both emp_no and email are different for every employee and never NULL. Name and dept may be the same as those of other employees. Which lists all the candidate keys of this table?
- Aemp_no only
- Bemp_no, and email (each one a candidate key on its own)
- Cemp_no, and the combination of emp_no and name
Show answer and explanation
Answer: B. emp_no, and email (each one a candidate key on its own)
A candidate key is a minimal set of columns that can uniquely identify a row: removing even one column from it would make unique identification impossible. In this table both emp_no and email can uniquely identify an employee on their own, so both are candidate keys. One candidate key is chosen as the primary key (emp_no is the natural choice here), and the one not chosen, email, is called an alternate key. Giving the alternate key UNIQUE and NOT NULL constraints prevents duplicates. The combination of emp_no and name can also identify a row uniquely, but uniqueness is kept even without name, so it is not minimal and therefore not a candidate key. A set of columns that identifies rows uniquely but is not necessarily minimal is called a superkey.
- A. Only one is chosen as the primary key, but there are two candidate keys, including email.
- B. Correct. Each can uniquely identify a row on its own and is minimal, so both are candidate keys.
- C. The combination of emp_no and name stays unique even without name, so it is not minimal and not a candidate key.