Foreign Key with NO primary key to refer

时间秒杀一切 提交于 2019-12-04 03:47:47

问题


I have following two tables.

CREATE TABLE parent
( c1 INTEGER );

CREATE TABLE child
(
 c1 INTEGER,
 c2 INTEGER,
 c3 INTEGER,
 CONSTRAINT fk_c3 FOREIGN KEY(c3) REFERENCES parent(c1)
);

You must have noticed that column c1 is NOT a primary key in Parent table. Is there any way to refer it in Child table without making c1 as a primary key?


回答1:


Is there any way to refer it in Child table without making 'c1' as a primary key?

Yes. A foreign key needs only to refer to a unique constraint - it does not have to be a primary key. You could create a unique contraint on that column.



来源:https://stackoverflow.com/questions/12819719/foreign-key-with-no-primary-key-to-refer

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