Last answered:

10 Jun 2024

Posted on:

08 Jun 2024

0

Resolved: SQL DDL statement

in the employees data base, salaries table ,  you set up ''emp_no'' column as a primary key , upon cheking the table i see dublicate values on ''emp_no'' column , why?

2 answers ( 1 marked as helpful)
Instructor
Posted on:

10 Jun 2024

0

Hi Lyes!
Thanks for reaching out.


I understand your confusion. In this case the PK is composite. This means that the combination of the columns emp_no and from_date should be unique. It is designed this way, because in the salaries table we would like to have multiple records for an employee because during his career he has changed a lot of jobs and salaries. So, we have to broaden the uniqueness to two columns - emp_no and from_date. Example:
emp_no | salary | from_date | to_date
10001    | 15000 | 2020-02-03 | 2021-02-04
10001    | 17000 | 2022-07-06 | 2023-05-05

So, we can use multiple times the same emp_no recording the different salaries. But the from_date is for the current job. So, this is why the composite PK consists of two columns. I apply a screenshot of the Indexes tab for the current table.


Hope this helps.
Best,
Tsvetelin

Posted on:

10 Jun 2024

0

thank you for your answer.

from what i learned in this cours, the primary key  is a column of the table that identifies every record that should be unique in the table and should not contain any duplicate values.


mes sinceres salutations.

Submit an answer