Foreign Key with NO primary key to refer

2019-02-24 18:11发布

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条回答
趁早两清
2楼-- · 2019-02-24 18:49

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.

查看更多
登录 后发表回答