3 个表之间的一对一关系(背靠背 - 1 对 1 关系)
有3张表,分别是FN、ADM、USR,分别代表一个 功能、功能管理员、参加功能的用户。 Admin 将是一个用户,ADM 必须从 USR 继承。
FN_I,USR_I 应该是 FN 和 USR 的主键。(这被许多其他表引用)
ADMN 是新添加的
我需要实现以下约束。
1. 一个功能只能有一个管理员。(1-1)
2. 一名管理员只能管理一项功能。(1-0/1)
我尝试通过将 FN_ADM_I 设置为 FN_I 的外键来实现 1。
有人可以帮助我解决可以实现这两个要求的约束/关系吗?
There are 3 tables namely FN, ADM, USR representing a
function, admin for the function, users who attend the function.
Admin will be a user and ADM has to be inherited from the USR.
FN_I,USR_I should be the prim key for FN and USR.(This is referenced by many other tables)
ADMN is the new able added
I need to implement the following constraints.
1. One Function can have only one admin.(1-1)
2. One Admin can administer only one Function.(1-0/1)
I tried achieving 1 using by setting FN_ADM_I as foreign key to FN_I.
Could some one help me with constraints/relationships that can achieve both the requirement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能想要创建一个链接表:
其中两个字段都是具有 UNIQUE 约束的主键:
You may want to create a link table:
where both fields are primary key with UNIQUE constraint:
我认为您在这里混淆了术语。我认为1-1(一对一)的关系并不完全是你想象的那样。
无论如何,如果我正确理解你的问题(很可能不是这种情况),这就是你所做的。
这有道理吗?
I think that you mixed up terminology here. I think 1-1 (one to one) relationship is not exactly what you think it is.
Regardless, if I understood your question correctly (which very easily might not be the case) here is what you do.
Does this make sense?