I am new to postgres i am creating a table with multiple primary keys
CREATE TABLE tab1(
col_1 int,
col_2 txt,
col_3 txt,
PRIMARY KEY (col_1,col_2)
);
I am trying refer one of the primary in table "tabl" as foreign key in another table
CREATE TABLE tab2 (
col_4 int,
col_5 txt,
col_6 numeric(5,2),
PRIMAY KEY (col_4),
CONSTRAINT fk_tab1 FOREIGN KEY(col_5) REFERENCES tab1(col_1) ON DELETE SET NULL
);
But when i am trying to do this i am getting error as below
ERROR: there is no unique constraint matching given keys for referenced table "tab1"
SQL state: 42830
How can i take one key among multiple primary keys in one table as foreign key in another table.