考虑这样的情况,我试图为一家公司建模一个数据库:
- 实体:
Employees
、Managers
、Departments
. -
Employee
只在1Department
中工作,而Department
可能有很多Employees
在其中工作. -
Manager
可以仅管理1Department
,类似地,Department
可以仅具有1Manager
. -
Manager
可以管理多个Employees
,而Employee
只能管理一个Manager
.
Now I have 2 ways to model this:个
100
我将考虑Manager
个实体从Employee
个实体继承,考虑到我将保留对管理者来说唯一的数据(例如, prize 和状态).
-
由于
Department
和Employee
之间的关系是1:N
,那么我将把Department Id
作为Works
的Employee
表中的外键 关系. -
由于
Department
和Manager
之间的关系是1:1
,那么我将把Department Id
作为Manages
的Manager
表中的外键 关系.
Problem: How can I represent the recursive relation between the 100 and 101?
100
I'll consider that the Manager
entity is not needed as other Employees
may also have a Bonus
and Status
. (Actually I added these 2 attributes just to see how to model it in both cases)
- 由于
Department
和Employee
之间的关系是1:N
,那么我将把Department Id
作为Works
的Employee
表中的外键 关系. - 既然
Employee
和Manager
之间的关系是1:N
,那么我将把
Problem: How can I represent the relation between the 100 and 101?
问题:
- 这两种设计都有明显的错误吗?
- 如何解决这两种情况下的每个问题?
- 有比这两个更好的解决方案吗?