通过sql中的单个列引用多个表

Pra*_*eek 3 sql foreign-keys

在SQL中,表中的单个列可以引用多个表吗?

例如,如果我们有表employee(PK emp_id, name) 和customer(PK cust_id, name)

我们可以有一张桌子吗contact(id 参考文献[employee, customer], number);

或者我们是否需要制作两张表:

contact_custcust_id参考文献customer, number)和contact_empemp_id参考文献employee, number

我知道即使第一个选择可行,第二个选择也会更好。我只想知道第一种方法可行吗?

Dis*_*ned 7

不,你不能。一种选择是首先将员工/客户概括为“一方”或“利益相关者”。
IE

TABLE: Party(PK Party_Id,
             Name)  
TABLE: Employeee(PK Emp_Id REFERENCES Party.Party_Id, 
                 Salary)  
TABLE: Customer(PK Cust_Id REFERENCES Party.Party_Id,
                CreditRating) 
Run Code Online (Sandbox Code Playgroud)

然后联系人将引用当事人。