问题
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