begin tran
select top 100 id from A with (rowlock,readpast) order by getnum
(之前加过newid(),虽然取随机记录大大降低并发率,但是CPU有点吃不消,所以放弃)
然后游标
update A set getnum=getnum+1 where id=@id --更新给出次数
@allid=@allid+','+@id --记录所有取出的ID
commit tran
select * from A where id in (@allid) --返回此次取出记录的记录集
update t
set t = case when (id + 100) % @c < 100 then 0
else (id + 100) % @c
end --更新这条记录,比如一开始是0,那么经过计算就是100
--选出第i+1 ~ i+100,比如一开始i是0,那么就是1~100
select id
from
(
select id,row_number() over(order by getnum) rownum from A
)t
where rownum between @id+1 and @id+100