Reputation: 163
I have two table like this:
tblGender
and TblPerson
I want to set foreign key for GenderID
.. but I'm getting this error:
The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "tblPerson_GenderID_FK". The conflict occurred in database "Sample", table "dbo.tblGender", column 'id'.
Upvotes: 1
Views: 1514
Reputation: 26784
You might have records in tblGender
which don't have match in tblPerson
on their respective columns.Try emptying the tables if that is an option.
Upvotes: 4
Reputation: 979
This is the script to add foreign key constraint.
alter table TblPerson
add constraint tblPerson_GenderID_FK FOREIGN KEY ( GenderID) references tblGender(id)
Upvotes: 0