Skip to content
Advertisement

Foreign Key Used in Composite Primary Key

Is it possible to use a composite foreign key as a piece of a table’s composite primary key?

For instance, let’s say I have two tables:

… and then in a second table, I would like to reference the foreign key in the second table’s primary key:

Is there any way that I can do that? Yes, it might be easier to just simply use IDENTITY columns in these tables but if I can define an actual relationship without an IDENTITY I would like to do that.

EDIT:

I wanted to provide the final, working SQL. Thanks to everyone who answered!

Advertisement

Answer

You probably need to specify the columns that are supposed to match.

So you need to provide the five column names whose values are supposed to match the values of {Name, City, State, Country, PostalCode} in the table “Partners”. i’m pretty sure youcan’t do that with your current structure. You won’t be able to match “Name”. I think you’re looking for something along these lines.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement