SQL Server 2008: The columns in table do not match an existing primary key or unique constraint

It means that the primary key in tblOne hasn't been properly declared - you need to go to tblOne and add the PRIMARY KEY constraint back onto it.

If you're sure that tblOne does have a PRIMARY KEY constraint, then maybe there are multiple tblOne tables in your DB, belonging to different schemas, and your references clause in your FK constraint is picking the wrong one.

If there's a composite key (which your comment would indicate), then you have to include both columns in your foreign key reference also. Note that a table can't have multiple primary keys - but if it has a composite key, you'll see a key symbol next to each column that is part of the primary key.


If you have a composite key the order is important when creating a FK, and sometimes the order is not how it is displayed.

What I do is go to the Keys section of the table1 and select script primary key as create to clipboard and then create FK using the order as shown in script


If you still get that error after you have followed all advice from the above answers and everything looks right.

One way to fix it is by Removing your Primary keys for both tables, Save, Refresh, and add them again. Then try to add your relationship again.


I've had this situation that led me to this topic. Same error but another cause. Maybe it will help someone.

Table1
ColA (PK)
ColB (PK)
ColC


Table2
ID (PK)
ColA
COLB

When trying to create foreign key in Table2 I've choose values from combobox in reverse order

Table1.ColB = Table2.ColB
Table1.ColA = Table2.ColA

This was throwing me an error like in topic name. Creating FK keeping order of columns in Primary key table as they are, made error disappear.

Stupid, but.. :)


This Error happened with me When I tried to add foreign key constraint starting from PrimaryKey Table

Simpy go to other table and and create this foreign key constraint from there (foreign key Table)