[SQL Server] 循环游标执行-无事务

From: https://blog.csdn.net/weixin_42609389/article/details/126955029

begin
    declare @a int
    declare @temp varchar(50)
    set @a=1
    
    declare order_cursor cursor for (select [CMID] from [Warehouse].[MT].[Customers])
    
    open order_cursor
    
    fetch next from order_cursor into @temp
        
        while @@FETCH_STATUS = 0    
        begin            
            update [Warehouse].[MT].[Customers] set CMCode=@a where [CMID]=@temp
            set @a=@a+1
            fetch next from order_cursor into @temp   
        end   
    close order_cursor  
    deallocate order_cursor   
end
go

  

 

posted on 2023-01-05 22:29  清清飞扬  阅读(29)  评论(0)    收藏  举报