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

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
Updated 28-Nov-11 19:14pm

Have a look at below links for information on "FOREIGN KEY Constraint".
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

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