表A中有40W条数据, 有120个字段,其中需要更新110个字段 表B有7W条数据,100个字段现在更新A表(存储过程)update A set A.1 = B.1 ... from A inner join b where a.xxx = b.xxx现在在别的程序中调用此 存储过程,有什么好的更新方法吗?谢谢!
现在就是在分批更新再问一下, view 是由 B1,B2 2个表结合而来 B1 的index 是 Item B2的index 是 To,refRecId, From那么A表跟B表结合的时候,是不是应该按照 update a left join B on B.TO = A.To and B.RefId = A.refId and B.From = A.From这样写才能有效的利用index,理解的对不?
update A set A.1 = B.1 ... from A inner join b on a.xxx = b.xxx
(一)a.xxx和b.xxx都要建上索引(最好是聚集索引),试试能否成功。
(二)在(一)的基础上,改用游标循环B,逐条更新A,每1000条作为一个事务递交。
a.xxx、b.xxx都加索引,应该能快很多
不能加索引吧
如果是join出来的view,对原表加索引也有效
如果是union出来的view,索引无效!
view 是由 B1,B2 2个表结合而来
B1 的index 是 Item B2的index 是 To,refRecId, From那么A表跟B表结合的时候,是不是应该按照
update a
left join B
on B.TO = A.To
and B.RefId = A.refId
and B.From = A.From这样写才能有效的利用index,理解的对不?
set A.1 = B.1
...
from A
inner join b on a.xxx = b.xxx