【发布时间】:2014-05-14 18:19:52
【问题描述】:
我有一个下表结构
Table1 Table2 Table3
--------------------------------
sId sId sId
name x y
x1 x2 x3
我想根据 sId 从 table1 中删除所有在 table3 中没有匹配记录的记录,如果 table2 中存在 sId,则不要从 table1 中删除记录。table1 中大约有 20,15 和 10 百万条记录,table2 & table3 分别 --我做过这样的事情
Delete Top (3000000)
From Table1 A
Left Join Table2 B
on A.Name ='XYZ' and
B.sId = A.sId
Left Join Table3 C
on A.Name = 'XYZ' and
C.sId = A.sId
((我在 sId 上添加了索引,但在 Name 上没有。)) 但这需要很长时间才能删除记录。 有没有更好的方法来删除数百万条记录? 提前致谢。
【问题讨论】:
-
你的索引是什么样的?希望您的
sId字段上有一个聚集索引? -
@JNK --Yes sId 字段有聚集索引
标签: sql sql-server tsql