Blog Pages

The ALTER TABLE statement conflicted with the FOREIGN KEY constraint. The conflict occurred in database , table , column

Error message:
The ALTER TABLE statement conflicted with the FOREIGN KEY constraint. The conflict occurred in database , table , column
Explanation:
Some foreign values do not exist in primary table.
Solution:
Make your table empty, or add the associated value to the primary key table.

A query to find the missing values:
SELECT F.* FROM ForeignTableName F
LEFT JOIN PrimaryTableName P on F.FKcolumn = P.PKcolumn
WHERE P.PKcolumn is null

3 comments:

  1. thank you
    I would not have thought of this for a few hours or days :)

    ReplyDelete
  2. thank you
    I would not have thought of this for a few hours or days :)

    ReplyDelete
  3. Thanks a lot for the query, you are the boss.

    ReplyDelete