Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a foreign key which references an entire composite key?

I have two tables one has a three column composite key. The other needs to reference this composite key.

What is the syntax for creating a foreign key which references multiple columns.

I tried googleing, but I couldn't find it.

like image 296
Eric Haskins Avatar asked Dec 13 '08 01:12

Eric Haskins


1 Answers

FOREIGN KEY (col1, col2, col3) REFERENCES ParentTable (colA, colB, colC)

Look under "<table_constraint>" in the online docs for Microsoft SQL Server CREATE TABLE.

like image 139
Bill Karwin Avatar answered Nov 15 '22 05:11

Bill Karwin