Creating a composite foreign key in SQL Server 2008

Viewed 84109

I have two tables that I'd like to create a foreign key for.

Primary Table

PK - Key1 - varchar(20)
PK - Key2 - date

Secondary Table

PK - AutoID
FK - Key1 - varchar(20)
FK - Key2 - date

When I try to create the relationship between the primary and secondary table, I keep getting the message

The columns in the Primary Table do not match a primary key or unique constraint.

There can be many records in the secondary table with the same Key1 and Key2 so we made the primary key an auto created number.

Any thoughts on how I can set up the foreign key relationship between these two tables?

5 Answers
Related