两个表之间可以有两个关系吗? [英] Can there be two relationships between two tables?

查看:69
本文介绍了两个表之间可以有两个关系吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个表:EMPLOYER和EMPLOYEE.由于每个雇员都分配给一个雇员,因此它们之间是1:N的关系-简单的东西. 但是我还希望能够建立一个模型,在这种情况下,每个雇员都可以选择他的一个最喜欢的雇员(他也可以不选择任何一个).

There are two tables: EMPLOYER and EMPLOYEE. Since each EMPLOYEE is assigned to one EMPLOYER there's 1:N relationship between them - simple stuff. But I also want to be able to model a situation where each EMPLOYER may be able to choose his one favorite EMPLOYEE (he might as well choose none).

我也应该:
1.在这些表之间添加第二个1:1关系-这样EMPLOYER还将包含EMPLOYEE_id_FK. 两个表之间是否允许两个关系?
2.添加由两个唯一的主键-EMPLOYER_ID和EMPLOYEE_ID标识的第三个表FAV.这样,我可以确定每个雇主只能有一个最喜欢的雇员,并且每个雇员也只能被一名雇员选为最喜欢的人-这正是我想要的.

So should I:
1. Add a second 1:1 relationship between those tables - this way EMPLOYER would also contain EMPLOYEE_id_FK. Is having two relationship between two tables even allowed?
2. Add a third table FAV identified by two primary, unique keys - EMPLOYER_ID and EMPLOYEE_ID? This way I would be sure each employer could only have one favorite employee and also each employee may be chosen as a fav only by one employee - which is exactly what I wanted.

做这件事的正确方法是什么?

What's the proper way to do it?

推荐答案

我的建议是拥有四个表.一个雇员表,一个雇主表,一个将雇员与雇主联系起来的表(谁说一个雇员不能为两个雇主工作),最后是一个将雇主与自己喜欢的雇员联系起来的表.

My recommendation is to have four table. One employee table, one employer table, a table to relate employee to employer (who says an employee can't work for two employers), and finally a table to relate an employer to their favorite employee.

是的,当然,在两个表之间可以有两个关系.

Yes, of course there can be two relationships between the same two tables.

这篇关于两个表之间可以有两个关系吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆