DECLARE @count int; DECLARE @limit int; DECLARE @totalcount int; set @totalcount=0; set @limit=10000; set @count=@limit; while @count=@limit begin --更新或删除SQL top、limit和@count请保持一致 start update [dbo].[table_name] set state_index=0 where id in (select top 10000 id from table_name where state_index is null) --更新或删除SQL end set @count=@@ROWCOUNT set @totalcount=@totalcount+@limit; print '时间:'+convert(varchar(16), getdate(),120)+' 本次数量:'+convert(varchar(10), @count)+' 总数量:'+convert(varchar(10), @totalcount) end