Alexander Kleinhans
Alexander Kleinhans

Reputation: 6248

Syntax to alter and create composite foreign key in postgres

I have a table in Postgres with a composite primary key.

What's the syntax to alter another existing table to add a composite foreign key to the composite primary key of the first table?

Upvotes: 3

Views: 2162

Answers (1)

Dan Ganiev
Dan Ganiev

Reputation: 1062

ALTER TABLE my_fk_table
ADD CONSTRAINT my_fk 
FOREIGN KEY (pk1, pk2) 
REFERENCES my_pk_table
ON DELETE CASCADE;

Upvotes: 5

Related Questions