myTable有列Id, Name, Type, MediaName, Folder
blacklistTable有列Id, Media
DELETE FROM myTable
WHERE Name = "Missing" AND Type = "Movie"
基本上,我想从myTable中删除与WHERE
语句匹配的所有项目,对于删除的每个项目,我想在黑名单表中添加一列,其中包含已删除的项目Id
和{{ 1}}。有没有一些巧妙的方法来做到这一点?
答案 0 :(得分:1)
您可以在删除数据之前执行SELECT INTO。
或者您可以将OUTPUT clause与INTO子句一起使用,例如
DELETE FROM MyTable
OUTPUT DELETED.Id, DELETED.MediaName INTO Blacklist
WHERE Name = "Missing" AND Type = "Movie"