The ALTER TABLE statement conflicted with the FOREIGN KEY constraint

 if this error occurs this means there data doesnt match with foreign key of referenced table


with No Check can be used.

 

alter table Department with nocheck add CONSTRAINT fk_departs FOREIGN key(DepartmentHead)
REFERENCES Employee(EmpId)

 

This is not recomended

Drop the constraint with nocheck and you can latter use with check after correcting the data 

alter table Department with check add CONSTRAINT fk_departs FOREIGN key(DepartmentHead)
REFERENCES Employee(EmpId)

Comments