SQL Server 2008 中单个列上的多个外键约束 [英] Multiple foreign key constraints on a single column in SQL Server 2008
问题描述
我有两个表 TableA 和 TableB.现在 TableA 有 2 列:ID &Name,TableB 有 3 列:ID,Name,&表AID.现在有一个来自 TableA.ID = TableB.TableAID 的外键约束.我需要能够允许 TableB.TableAID 使用来自 TableA.ID 或 TableB.ID 的值,因此单个列上有多个外键约束,我需要它允许或.谢谢!
I have two tables TableA and TableB. Now TableA has 2 columns: ID & Name, TableB has 3 columns: ID, Name, & TableAID. Now there is a foreign key constraint from TableA.ID = TableB.TableAID. I need to be able to allow for TableB.TableAID to either use values from TableA.ID or TableB.ID, hence multiple foreign key constraints on a single column and I need it to allow either or. Thanks!
推荐答案
这是糟糕设计的明显标志.您永远不需要这样做,如果您这样做了,那么您需要重新考虑您的设计.
That is a clear sign of a bad design. You should never need to do this and if you do then you need to rethink your design.
您不能将一个字段与两个不同的 FK 相关联.
You cannot make a field be associated with two different FKs.
这篇关于SQL Server 2008 中单个列上的多个外键约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!