外键紧急帮助 [英] Foreign Key Urgent Help

查看:113
本文介绍了外键紧急帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您引用主表的复合主键,则必须引用复合主键的所有字段。

但是如何在子表中部分引用复合主键?例如,如果Table1有主键(A,B,C),那么
如何在表2中创建一个外键,它只引用Table1的(A,B)字段?



提前感谢,

解决方案

你可以这样做,但是:

1)你可以添加对唯一属性集的引用。

2)作为主键,(A,B,C)是唯一的。

3)如果你想添加对(A,B)的引用,它必须是唯一的

4)如果(A,B)是唯一因此是主键候选者,为什么(A,B,C)毕竟是主键?



我闻到了设计问题。请参考以下文章: http ://www.sqlmag.com/article/systems-administrator/sql-by-design-how-to-choose-a-primary-key-5113 [ ^ ]

If you refer a composite primary key of a master table, you have to refer all the fields of the composite primary key.
But how to partially refer the composite primary key in a child table? For example, if Table1 has primary key (A,B,C),
how to create a foreign key in Table2 which will refer only (A,B) fields of Table1?

thanks in advance,

解决方案

You can do this, but:
1) You can add reference to a property set that is unique.
2) As primary key, (A,B,C) is unique.
3) If you want to add reference to (A,B), it has to be unique
4) If (A,B) is unique thus a primary key candidate, why is (A,B,C) the primary key after all?

I smell a design problem. Please consult the following article too: http://www.sqlmag.com/article/systems-administrator/sql-by-design-how-to-choose-a-primary-key-5113[^]


这篇关于外键紧急帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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