更新时间:2023-02-05 09:46:31
还有另一种循环方式.我已经看到很多答案将计数器加 1.但是,根据我的经验,不能保证您在数据集中的 id 不会有间隙.
There is another way to loop. I've seen a lot of answers increment the counter by 1. However, in my experience, there is no guarantee that your ids in the dataset won't have gaps.
这是我经常使用的解决方案:
Here is a solution that I often use:
declare @idColumn int
select @idColumn = min( TableID ) from Table
while @idColumn is not null
begin
/*
Do all the stuff that you need to do
*/
select @idColumn = min( TableID ) from Table where TableID > @idColumn
end