SQL - Foreign Key Constraint Error with Update Statement
14,708
In all the possible scenarios, you are either trying to insert a NULL
value in your table or a value that does not exist in the reference table.
Most of the time, it is because you are trying to insert the NULL
value in the field.
Author by
343
Updated on June 04, 2022Comments
-
343 almost 2 years
I am Trying to update my table (product) columns - ProductID(FK) and ProductType(FK). These two column has relation with MProduct table's column MProductID(PK) and MProductType(PK).
I am trying to update
ProductID ProductType 9999 11 9999 12
But I got the following error
The UPDATE statement conflicted with the FOREIGN KEY constraint "FKHCR_MProduct". The conflict occurred in database "XXXX", table "dbo.MProduct".
I checked with MProduct table, It has all the valid records for look up. I can not change my Table Structure.
I tried this Query too
Select ProductID,ProductType from dbo.Product P Left Join dbo.MProduct M on M.ProductID = P.ProductID and M.ProductType = P.ProductType where M.ProductType is null and M.ProductID is null
and there is No Output, means there is No Null Data Inside the Look up table.