如何建模这个数据库关系? (Sybase PowerDesigner)
I'm doing a conceptual model in Sybase PowerDesigner. The restriction is following: One doctor can work in only one office at a time during his working time (shift). I guess Doctor - Office relationship should be many-many, but what about time restriction ("during his working time")? Should it be a new table SHIFT? So I guess I should have four tables (DOCTOR, OFFICE, SHIFT and OFFICE SCHEDULE). OFFICE SCHEDULE should be a table connecting all 3 other entities and should have composite primary key (id_doctor, id_office, id_shift)?
I'm doing a conceptual model in Sybase PowerDesigner. The restriction is following: One doctor can work in only one office at a time during his working time (shift). I guess Doctor - Office relationship should be many-many, but what about time restriction ("during his working time")? Should it be a new table SHIFT? So I guess I should have four tables (DOCTOR, OFFICE, SHIFT and OFFICE SCHEDULE). OFFICE SCHEDULE should be a table connecting all 3 other entities and should have composite primary key (id_doctor, id_office, id_shift)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该密钥(id_doctor、id_office、id_shift)允许医生轮班在多个办公室工作。尝试将医生和轮班办公室的表作为依赖字段。然而,这将允许一个办公室有多名医生轮班,我不确定这是否被允许。
That key (id_doctor, id_office, id_shift) would allow a doctor to work in many offices in one shift. Try a key for that table of doctor and shift - office being a dependent field. However this would allow an office to have multiple doctors in a shift and I am not certain if that is allowed.
OFFICE SCHEDULE 的主键应该是 (id_office, id_shift)。 id_doctor 应该在表中,但不是主键的一部分。这将强制执行这样的规则:给定一个办公室并轮班后,该办公室最多只能有一名医生。
当然,除了构成主键的两个之外,所有这三个都是外键。
The primary key of OFFICE SCHEDULE should be (id_office, id_shift). id_doctor should be in the table, but not part of the primary key. This will enforce the rule that given an office and given a shift there can be at most one doctor in that office.
Of course, all three of these are foreign keys in addition to the two that form the primary key.
我会将您的主键更改为仅包含办公室和轮班,同时还对医生和轮班添加单独的独特约束。
I would change your primary key to only include office and shift, but also add a separate unique contraint on doctor and shift together.