2011-09-04 61 views
0

我有一个过程更新表中的2000多行。我需要使存储过程批量运行

我需要使该过程批量运行。我希望它能在前10行,接下来的10行上运行,依此类推。请我如何去做。

+1

你尝试过什么到目前为止? –

+0

实际目标是什么?你是否发现,当你更新所有2000行(这是微小的,顺便说一句)有性能问题?也许人们可以看看你的更新声明中可能的优化,而不是跳到关于解决方案必须是什么的结论。 –

回答

0

喜欢的东西:

declare @id int 
declare c cursor for 
    select top 10 id 
    from table 
    where (needs updating) = 1 

open c 
fetch next from c into @id 
while @@fetch_status = 0 
begin 

    update table 
    set 
    (needs to be set) = (value to set), 
    (needs updating) = 0  
    where id = @id 

    fetch next from c into @id 

end