0

Maybe this is not the best way to go about this ... But if it is I want to check as I have not seen any EER models showing this.

Say you have the entities Employees, Managers and Workers

An employee is either a manager or a worker

employees(Username PK, password, name)

manager(manager_ID PK, shift, department)

workers(worker_ID PK, hour_per_week, manager_ID FK)

Can I insert ID as a attribute to employees which is the primary key of either manager or worker.

Or do I add username as a foreign key to both managers and workers

Basically how do I link employees to both workers and managers depending on who they are?

4

1 回答 1

1

我可以插入 ID 作为员工的属性,它是经理或工人的主键。

不,员工列中的主键是'1'指哪个?经理 ID 还是工人 ID?这两个表可能都有 ID 为 1 的条目,因此除非您添加另一列,例如is_manager.

或者我是否将用户名作为外键添加到经理和工作人员。

是的 - 员工 PK 应该是 和 的managerFK employees。事实上,您不需要为经理或员工额外/单独的 PK,因为您可以重复使用员工 PK。

此外,即使您使用“用户名”作为 PK,如果可以更改,最好将 PK 保留为数字。

于 2013-08-18T15:15:32.077 回答