Foreign key without primary key for reference

I have the 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 NOT the primary key in the parent table. Is there a way to refer to it in the Children table without making c1 as the primary key?

+4
source share
1 answer

Is there any way to refer to it in the Children table without making "c1" as the primary key?

Yes. A foreign key only needs to refer to a unique constraint - it does not have to be a primary key. You can create a unique contrast in this column.

+6
source

Source: https://habr.com/ru/post/1438887/


All Articles