【发布时间】:2017-03-31 14:39:05
【问题描述】:
以下代码从表中删除与非活动项目相关的任务记录。
delete from [Deliverables] where
[Deliverables].[ProjectID] not in
(
select
[ProjectID] from [ActiveProjects]
)
我在某处读到,将NOT IN 与返回大量值的子查询一起使用并不是最有效的做法,最好使用EXCEPT 子句。
但是,当我尝试使用以下代码时,出现错误(关键字“except”附近的语法不正确。)
delete from [Deliverables]
except
select * from [Deliverables], [ActiveProjects]
where [Deliverables].[ProjectID] = [ActiveProjects].[ProjectID]
如何将EXCEPT 与DELETE 一起使用?如果我不能,有什么方法可以优化我的查询以更快地执行?
【问题讨论】:
标签: sql sql-server-2008 tsql query-optimization