Adding Foreign Key - Error

  • I received the following error when I attempted to add a foreign key to a table:

    .....The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_EjectorData_HeatId_Heat". The conflict occurred in database "SPDW", table "DG.Heat", column 'HeatId'.

    I got around the problem by deselecting "Check Existing Data" in the GUI for adding a key, but that certainly didn't feel right. I don't understand what the conflict was. An explanation would be appreciated.

  • The error is simply stating that the field that you applied the constraint to contains values that do not exist in the table that the constraint references.

    Regards,

    Jason P. Burnett
    Senior DBA

  • A quick check of the two small test tables involved confirms your explanation.

    The primary table has HeatIds = 0..18

    The secondary table has HeatIds = 1..19

    I can't understand how that happened. Thanks for a clear concise explantion.

  • No problem, glad to help. 🙂

    Regards,

    Jason P. Burnett
    Senior DBA

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply