简单的MERGE语句不起作用

时间:2014-10-19 21:22:58

标签: sql-server tsql

我无法弄清楚我做错了什么。

MERGE dbo.[table1] target
USING (SELECT [qId], [cId], [deleted] FROM dbo.[table1]
    WHERE [qId] = 1 AND [cId] = 2) source
    ON (target.[qId] = source.[qId] AND target.[cId] = source.[cId])
WHEN MATCHED THEN
    UPDATE SET target.[deleted] = 0
WHEN NOT MATCHED BY TARGET THEN
    INSERT ([qId], [cId]) VALUES (1, 2);

[qId] = 1 AND [cId] = 2 [table1]中存在UPDATE组合时,INSERT会执行{{1}},但如果组合不存在,则{{1}}不会发生。

0 个答案:

没有答案