Reputation: 8580
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)?
Upvotes: 2
Views: 108
Reputation: 1269513
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.
Upvotes: 4