use DBA go CREATE PROCEDURE [dbo]. [UP_PromotionsCode20131218_single] @id int , @batch int = 2000 AS SET NOCOUNT ON; UPDATE b SET CId = a. CId , GetCodeDate= GETDATE () , Status = 1 FROM _dba . dbo. Code20131218 a WITH( NOLOCK ) INNER join _dba. dbo .Code20131218_test b with (nolock ) on a . Code = b . Code WHERE A . ID between @id and @id + @batch - 1
調用腳本以下:web
--- 使用如下腳本調用 declare @id int = 1, @batch int = 100 ; select @id = min( a .id ) FROM dbo . PromotionsCode20131218 a WITH ( NOLOCK) INNER join dbo. PromotionsCode b with( nolock ) on a . PrmotionCode = b . PrmotionCode WHERE B . Status = 0; while @id < 800000 begin ; EXEC [UP_PromotionsCode20131218_single] @id, @batch set @id = @id + @batch raiserror ('...%d' , 10, 1 , @id ) with nowait ; end ;