数据库设计-实体关系模型
我有以下问题需要表达。
有人员、工作场所和地点。每个人可以被分配到多个工作场所。每个工作场所可以有多人。每个工作场所只有一个站点。到目前为止,一切都很好。但我的问题是每个人在特定地点只有一个工作场所。
我如何在 ERM 中表达这一点?
到目前为止我的想法:
我只是无法表达“一个人在特定地点只有一个工作场所”-这种方法有问题。
实施解决方案:
Table Person with Prs_ID (PK)
Table Site with Site_ID (PK)
Table Workplace with Plc_ID (PK)
Table Person_Site with Prs_Site_PrsID (PK, FK), Prs_Site_SiteID (PK, FK), Prs_Site_PlcID (FK)
Unique Index on Prs_Site_PlcID
我认为这应该可以解决问题。 现在我该如何在 ERM 中表达这一点?
编辑:
我以为这可以解决问题,但事实并非如此。这样我就无法将一个工作场所分配给两个不同的人,因为 Prs_Site_PlcID 列上有一个唯一索引。回到最初...
I have the following problem that I need to express.
There are persons, workplaces and sites. Each person can be assigned to multiple workplaces. Each workplace can have multiple persons. Each workplace has exactly one site. So far so good. But my problem is that each person has only one workplace at a specific site.
How can I express this in an ERM?
My idea so far:
I just can't express the "one person has only one workplace at a specific site"-problem with this approach.
Implementation Solution:
Table Person with Prs_ID (PK)
Table Site with Site_ID (PK)
Table Workplace with Plc_ID (PK)
Table Person_Site with Prs_Site_PrsID (PK, FK), Prs_Site_SiteID (PK, FK), Prs_Site_PlcID (FK)
Unique Index on Prs_Site_PlcID
I think this should solve the problem.
Now how can I express this in an ERM?
Edit:
I thought it would solve the problem but it doesn't. With this I can't assign one workplace to two different persons, because there is a unique index on the Prs_Site_PlcID column. Back to the beginning...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
注意唯一索引
Ak1
(备用键)(SiteID, WorkplaceID )
在Workplace
上,并传播到PersonWorkplace
。Note unique index
Ak1
(alternate key)(SiteID, WorkplaceID)
onWorkplace
which is propagated toPersonWorkplace
.我认为线索就在问题中。
你说每个工作场所都有一个Site,那么关系就是:
多人有多个工作场所
一个工作场所有一个Site;
实现建议:
site_id 列上的唯一索引工作场所表中确保每个工作场所都与不同的站点关联。
I think the clue is in the question.
You say that each work place has one site - the relationships thus are:
many persons have many workplaces
One workplace has one Site;
Implementation suggestion:
The unique index on the site_id column in the workplace table ensures that each workplace is associated with a different site.
您需要一个中间表 EMPLOYEES,它代表一个人在工作场所为雇主工作的时间。一个人可以是多名雇员,即为多个雇主工作。白天工作/夜间工作,或连续工作。 EMPLOYEE 不是 person 实体的同义词,而是 person-at-employer 的表示。
YOu need an intermediate table EMPLOYEES which represents a PERSON's stint at a worksite working for an employer. A single person can be many employees, i.e. work for more than one employer. Day job / night job, or jobs in succession. EMPLOYEE is not a synonym for the person entity but is a representation of person-at-employer.