我有这个更新文件,我将新数据加载到我的数据库或更新现有数据。但我得到了这些错误。
The MERGE statement conflicted with the FOREIGN KEY constraint
"FK_JW_MaterialData2PL_cMat_MaterialText".
The conflict occurred in database "TEST", table "dbo.JW_MaterialData", column 'camosGUID'.
和
The MERGE statement conflicted with the FOREIGN KEY constraint
"FK_JW_MaterialData_cMat_Material". The conflict occurred in
database "TEST", table "dbo.cMat_Material", column 'camosGUID'.
这是相关的陈述。但是当然还有更多的MERGE
语句和更多表格。
MERGE INTO [dbo].[JW_MaterialData2PL] ON camosGUID
WHEN MATCHED THEN UPDATE SET
WHEN NOT MATCHED THEN INSERT
MERGE INTO [dbo].[cMat_Material] ON camosGUID
WHEN MATCHED THEN UPDATE SET
WHEN NOT MATCHED THEN INSERT
MERGE INTO [dbo].[JW_MaterialData] ON camosGUID
WHEN MATCHED THEN UPDATE SET
WHEN NOT MATCHED THEN INSERT
FK_JW_MaterialData2PL_cMat_MaterialText
和FK_JW_MaterialData_cMat_Material
设置为ON UPDATE CASCADE
和ON DELETE CASCADE
。
这可能是我放置MERGE
语句的顺序问题?或者你知道可能是什么原因吗?
另一个问题:当我再次运行脚本时,没有错误。那么只运行scipt两次还是会导致将来出现问题?
答案 0 :(得分:0)
有必要通过查看表的依赖关系以正确的顺序放置MERGE
语句。
cMat_Material
JW_MaterialData
JW_MaterialData2PL