单个外键引用同一表中的多个列 [英] Single Foreign Key Referencing Multiple Columns in Same Table

查看:130
本文介绍了单个外键引用同一表中的多个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个表的主键可以多次成为另一个表中的外键。请看下面的场景:



表:1

id(pk)

title

referenceID(FK)

oldreferenceID(FK)

 



表:2

referenceID(PK)

referenceTitle



在这里,我可以使用表:2 referenceID(PK)作为表:1 referenceID(FK)& oldreferenceID(FK)中的外键?



请指教。在此先感谢。

解决方案

是的,它绝对有效,一个表可以在几列中引用相同的主键。


是。这很正常 - 想想地址,例如:公司可能有一个账单地址和一个送货地址。您只需存储一次地址,并使用外键引用将它们附加到单个公司。每个地址都有一个不同的主键。


这可能对你有帮助:



http://stackoverflow.com/questions/18248366 / trigger-on-delete-on-update-for-table-with-many-columns-that-to-one-co [ ^ ]

Can a primary key of one table be a foreign key in another table more than one time. Please see the scenario below:

Table:1
id (pk)
title
referenceID (FK)
oldreferenceID (FK)


Table:2
referenceID (PK)
referenceTitle

Here, can i use "Table:2 referenceID (PK)" as foreign key in "Table:1 referenceID (FK) & oldreferenceID (FK) ?"

Please advise. Thanks in advance.

解决方案

Yes, it is absolutely valid, a table can reference the same primary key in several columns.


Yes. It's pretty normal - think of addresses for example: a company may have a Billing address and a Delivery Address. You would only store each address once, and use Foreign Key references to attach them to the single company. Each address would have a distinct Primary Key.


This maybe help you :

http://stackoverflow.com/questions/18248366/trigger-on-delete-on-update-for-table-with-many-columns-that-reference-to-one-co[^]


这篇关于单个外键引用同一表中的多个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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