Sql 从表中删除临时表中的记录
我在SQL中创建了一个包含重复记录的临时表 我想从主表中删除此临时表中包含的所有记录。我看到一些示例可以这样做,但它们似乎都是invovle选择的,我已经在临时表中进行了选择 以下是伪代码中的情况:Sql 从表中删除临时表中的记录,sql,tsql,Sql,Tsql,我在SQL中创建了一个包含重复记录的临时表 我想从主表中删除此临时表中包含的所有记录。我看到一些示例可以这样做,但它们似乎都是invovle选择的,我已经在临时表中进行了选择 以下是伪代码中的情况: DELETE FROM MyMainTable(unique and duplicate records) WHERE the record exists in #temp 您还可以执行以下操作: DELETE T FROM MyMainTable T WHERE EXISTS (SELECT *
DELETE FROM MyMainTable(unique and duplicate records) WHERE the record exists in #temp
您还可以执行以下操作:
DELETE T
FROM MyMainTable T
WHERE EXISTS (SELECT *
FROM #temp
WHERE T.id = #temp.id)
与您的问题一样,全球层面: 如果你的诱饵有原始的主id
Delete From Originaltable where primarykeyid in (select primarykeyid from temptable)
在我看来,使用带有联接的EXISTS通常会比使用INTANK获得更好的性能。感谢您的帮助。
Delete From Originaltable where primarykeyid in (select primarykeyid from temptable)