SQL - 更新语句的外键约束错误

时间:2021-01-01 09:26:30

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).

我正在尝试更新我的表(产品)列 - ProductID(FK)和ProductType(FK)。这两列与MProduct表的列MProductID(PK)和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.

我检查了MProduct表,它有所有有效的查询记录。我不能改变我的表格结构。

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.

并且没有输出,表示查找表中没有空数据。

1 个解决方案

#1


3  

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.

在所有可能的方案中,您要么尝试在表中插入NULL值,要么在参考表中不存在值。

Most of the time, it is because you are trying to insert the NULL value in the field.

大多数情况下,这是因为您尝试在字段中插入NULL值。

#1


3  

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.

在所有可能的方案中,您要么尝试在表中插入NULL值,要么在参考表中不存在值。

Most of the time, it is because you are trying to insert the NULL value in the field.

大多数情况下,这是因为您尝试在字段中插入NULL值。