我无法弄清楚我做错了什么。
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}}不会发生。