使用MSSQL 2005我习惯写这样的语句:
delete
from myTable
where ID in (select ID from otherTable where deleted = 1)
如果otherTable
有复合主键,我该怎么做?
复合键有两列:
docnum float
version int
(我的google-fu建议使用CTE执行此操作,但我没有经验。)
答案 0 :(得分:2)
在MS SQL中,您可以这样做:
DELETE T
FROM myTable T
INNER JOIN otherTable OT
ON T.docnum = OT.docnum
And T.version = OT.version
也有类似的更新语法。
答案 1 :(得分:1)
您还可以使用存在关键字:
delete t1
from myTable t1
where exists (
select * from otherTable where docnum = t1.docnum and version = t1.version
)