Click here to Skip to main content
15,907,395 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have two tables. when i tried to add a foreign key using this query


SQL
alter  table tbl_user_login add constraint fkcid foreign key(fk_Consumer_ID) references tbl_Consumer_details(Consumer_ID)



it shows an error:

There are no primary or candidate keys in the referenced table 'tbl_Consumer_details' that match the referencing column list in the foreign key 'fkcid'.


help me

thanks in advance
Posted
Updated 28-Nov-11 19:14pm
v5

Have a look at below links for information on "FOREIGN KEY Constraint".

http://www.w3schools.com/sql/sql_foreignkey.asp

http://msdn.microsoft.com/en-us/library/ms175464.aspx
 
Share this answer
 
this means your table 2 doesn't have a primary key to be referenced by table 1.

Assign a primary key first to the secondary table you are joining

Regards,
Eduard
 
Share this answer
 
Change Consumer_ID as Primary Key in the reference table
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900