SQL Server 2008 中单个列上的多个外键约束 [英] Multiple foreign key constraints on a single column in SQL Server 2008

查看:45
本文介绍了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屋!

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