Insert Error

  • Hello all,

    I am getting this error and I'm not sure why, could someone shed some light on it?

    "The INSERT statement conflicted with the FOREIGN KEY constraint "FK_SODetail_SOHeader". The conflict occurred in database "ReportingDB", table "dbo.SOHeader", column 'OrderId'.".

    Thanks for any help or advice!

  • marty.seed (2/1/2010)


    Hello all,

    I am getting this error and I'm not sure why, could someone shed some light on it?

    "The INSERT statement conflicted with the FOREIGN KEY constraint "FK_SODetail_SOHeader". The conflict occurred in database "ReportingDB", table "dbo.SOHeader", column 'OrderId'.".

    Thanks for any help or advice!

    It's because you're trying to insert some data that has some kind of conflict with your foreign key. For example, if your index is set up for unique records, you can't enter "foo" if "foo" already exists.

    I can't tell you anything more without seeing some sample data.

    +--------------------------------------------------------------------------------------+
    Check out my blog at https://pianorayk.wordpress.com/

  • That helps Ray! Thank you, I will look through the data and see whats up.

  • You're welcome! 🙂

    +--------------------------------------------------------------------------------------+
    Check out my blog at https://pianorayk.wordpress.com/

  • You are attempting to add a record to a child table that does not have a corresponding value in the parent table as defined in the Foreign Key.

    The error message tells you the column "Order_ID", simply query the parent table for the value that you are attempting to INSERT into the child Table.

    You can only define a relation to the parent table to the Priimary Key or Unique Constraint(s).

    You may query the following system tables and file on table name and column name to view information on the FK Contraint:

    sys.foreign_keys

    sys.foreign_key_columns

    sys.objects

    You may also use SMSS to view information about your constraint.

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Hi Welsh, this helped immensely, thank you

Viewing 6 posts - 1 through 5 (of 5 total)

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