【发布时间】:2013-06-23 08:07:05
【问题描述】:
我有 2 张桌子,例如:
-table1: id_1, id_2, id_3, ref_id (id_1, id_2 is pk)
-table2: ref_id, id_4
我希望 id_3 字段应该等于 table2 的 id_4(ref_id 是主键) table1 大约有 600 万条记录,table2 大约有 2700 条记录。
我写了一个类似的sql:
update table1
set id_3 = b.id_3
from table1
left join table2 b on id_1= b.ref_id
通过使用 SQL Server,查询需要花费 16 小时左右的时间,但仍然没有响应。如何减少查询时间?
【问题讨论】:
-
您在哪些列上有索引?可能是在更新大量索引数据之前删除一些索引的选项,然后在之后重建索引 - 如果可能的话,当然是(如果您不需要列值的强制唯一性或其他东西)。
-
我不认为这花了这么长时间,所以不存在索引。
标签: sql-server performance sql-update