For a composite foreign key, is a/why is a composite UNIQUE constraint in the referenced table required for a column combination with a primary key?

房东的猫 提交于 2019-12-02 04:14:48

It's more to do with the theoretical side of relational databases, actually.

What foreign key references in its parent table is not an arbitrary set of columns, however unique they might be; it references a key - either primary or alternate. And this key must be clearly declared as such.

Any superset of a unique column set is unique. DBMSs could be programmed to understand this. But SQL requires you to declare the combination unique in the referenced table anyway.

PS In the relational model a foreign key must reference a candidate key, which must both be declared. But in SQL, UNIQUE declares a superkey and FOREIGN KEY declares a foreign superkey. (When a superkey contains no smaller superkey it's a candidate key.) One could prefer for ergonomic redundancy that the target of a foreign superkey declaration have an explicit matching unique declaration. But there's no theoretical or implementation justification for that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!