Recreating Foreign Key

  • Msg 1776, Level 16, State 0, Line 1

    There are no primary or candidate keys in the referenced table 'Production.Product' that match the referencing column list in the foreign key 'FK_BillOfMaterials_Product_ComponentID'.

    Msg 1750, Level 16, State 0, Line 1

    Could not create constraint. See previous errors.

    A primary key ProductID is defined and exist in the table Production.Product as a clustered index.

    I am trying to create a foreign key on ComponentID referencing table Product and I get the above error.

    Below is my TSQL statement:

    ALTER TABLE [Production].[BillOfMaterials] WITH CHECK ADD CONSTRAINT [FK_BillOfMaterials_Product_ComponentID] FOREIGN KEY([ComponentID])

    REFERENCES [Production].[Product]([ProductID])

    When i create this foreign key from SSMS, it succeeds. Is there something i am doing wrong. Any help will be appreciated.

  • You are not being very clear here.

    When you successfully create it in SSMS, how are you creating it? In an Editor window? via the Designers?

    How are you creating it when it fails?

Viewing 2 posts - 1 through 1 (of 1 total)

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