|< < 21 > >|

Foreign keys

Multi-column foreign keys

The references syntax only works for a single-column FK/PK.

There is a more general syntax for use with a multi-column FK/PK.
create table P( p1_id int not null, p2_id int not null, x int, primary key(p1_id, p2_id) ); create table F( f_id int not null primary key, p1_id int, p2_id int, y int, foreign key(p1_d, p2_id) references P );

  • primary key(p1_id, p2_id): A 2-column PK.

  • foreign key(p1_d, p2_id) references P: A 2-column FK that refers to it.

|< < 21 > >|