首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

游标update表1700W行数据耗时四个小时还在执行

2012-08-10 
游标update表1700W行数据耗时4个小时还在执行CREATE PROCEDURE proc_update ASbegindeclare cur_updatecur

游标update表1700W行数据耗时4个小时还在执行
CREATE PROCEDURE proc_update AS
begin
declare cur_update cursor dynamic for select * from customer_cmb 
open cur_update 
  fetch first from cur_update
   
while @@fetch_status=0
begin

update customer_cmb set age = (case
when substring(id,7,4)like '%[a-zA-Z]%' then '0'
when len(id)=18 then year(getdate())-substring(id,7,4)
when len(id)=15 then year(getdate())-('19'+substring(id,7,2))
else '0'
 
end ) where current of cur_update
  fetch next from cur_update
  end
close cur_update
deallocate cur_update
end

存储过程中使用了游标,数据库是 sql2000, win7系统,问题RT。。。
望各位达人们帮帮忙...

[解决办法]
更新这么大的数据量 数据会锁表的
即便不用游标也会花费大量的时间。切忌在生产环境中执行。

分批次执行更新吧
[解决办法]

SQL code
直接执行不行吗:update customer_cmb set age = (casewhen substring(id,7,4)like '%[a-zA-Z]%' then '0'when len(id)=18 then year(getdate())-substring(id,7,4)when len(id)=15 then year(getdate())-('19'+substring(id,7,2))else '0'  end ) 

热点排行