问题描述
$ b $ pre $
FOREIGN KEY(a)参考A(a),FOREIGN KEY(b)REFERENCES A(b)
与
FOREIGN KEY(a,b)参考A(a,b)?
b $ b
有两个引用
语句意味着 a
和 b
独立出现在
A
中。也就是说,它们是有效的价值,但不一定要一起出现。想想二月三十日。有一个有效的月份和一个月的有效日期,当每个单独检查。
拥有一个引用
语句表示 a
和 b
出现在 A
一起。因此,2月30日将不能通过这个测试。传统上,外键指的是主键或唯一键。这不是在MySQL中强制执行的,但它是一个有用的指南(在实践中也是有用的)。因此,在两个引用
的例子中,这通常意味着 a
和 b
是唯一的。虽然这不是强制执行的,但它可以很好地说明如何使用这些密钥。在第二种情况下, a
和 b
的组合是唯一的。
Does
FOREIGN KEY (a) REFERENCES A(a),FOREIGN KEY (b) REFERENCES A(b)
Has the same meanning as in :
FOREIGN KEY (a,b) REFERENCES A(a,b)?
No.
Having two references
statement means that both a
and b
appear in A
independently. That is, they are valid values, but they don't have to appear together. Think of "February 30". It has a valid month and a valid day of month, when each are checked separately.
Having a single references
statement means that a
and b
appear in A
together. Hence, "February 30" would fail this test.
Traditionally, a foreign keys refer to a primary or unique key. This is not enforced in MySQL, but it is a useful guideline (and also useful in practice). So, in the example with two references
, this would usually mean that both a
and b
are unique. Although this is not enforced, it gives a good indication of how the keys will be used. In the second case, the combination of a
and b
is unique.
这篇关于SQL外键引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!