0

MySQL.

There is a table users with autoincrement primary key id.

There is also a table employees (every employee is a user but not vice versa). The employees primary key is userid. The field userid is not autoincrement.

employees.userid is a foreign key for users.id.

Thus every employee's primary key value is also users primary key value.

Now consider a third table rows of which should refer to an employee.

The question: Should the third table refer to users.id or to employees.userid?

  • You say "Now consider a third table rows of which should refer to an employee." – ypercubeᵀᴹ Apr 25 '13 at 14:52
2

If the third table is related to employees and not to every user, you should reference employees.userid.

It makes sense for, say, a table of employee identity card numbers to reference "employees"."userid". But it makes sense for a table of email addresses to reference "users"."userid", because every user has an email address.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.