【发布时间】:2017-12-31 13:16:41
【问题描述】:
我使用MERGE 到UPDATE 或INSERT 数据进入我的数据库。但是当我 MERGE 进入我的表 xx_MaterialData 或 xx_MaterialDataxxx 时,我得到如下所示的 FK 错误。
The MERGE statement conflicted with the FOREIGN KEY constraint
"FK_xx_MaterialData_xxxx_Material". The conflict occurred in database
"TEST", table "dbo.xxxx_Material", column 'xxxxxGUID'.
和
The MERGE statement conflicted with the FOREIGN KEY constraint
"FK_xx_MaterialDataxxx_xxxx_MaterialText". The conflict occurred in
database "TEST", table "dbo.xx_MaterialData", column 'xxxxxGUID'.
我已经尝试了 MERGE 语句的不同顺序,但没有帮助。我首先尝试了xxxx_Material,然后是孩子们。或者先是孩子xx_MaterialDataxxx,然后是xx_MaterialData,然后是xxxx_Material。
依赖项如下:
xxxx_Material > xx_MaterialData > xx_MaterialDataxxxxxxx_Material > xxxx_MaterialTextxxxx_PriceList > xx_MaterialDataxxx
有人知道我还能做什么吗?我有另一个具有相同结构但数据不同的数据库,我没有问题。
MERGE 语句的正确顺序是什么?也许我做错了什么?
【问题讨论】:
-
能否提供您的查询和表结构?
-
请在更新、插入、删除任何内容之前运行 SELECT 进行验证。谢谢。
标签: sql sql-server merge foreign-keys constraints