当前位置: 代码迷 >> SQL >> T_SQL利用游标遍历表记录,更新每条记要ID值
  详细解决方案

T_SQL利用游标遍历表记录,更新每条记要ID值

热度:12   发布时间:2016-05-05 11:30:16.0
T_SQL利用游标遍历表记录,更新每条记录ID值

利用游标遍历表,更新表记录

declare  @Id bigint

declare @count int

declare @eventIDvarchar(50)

 

set @Id = 4294967297

 

 

declare my_Cursorcursor local for

 

select EventCodefrom eventRule

 

open my_Cursor

 

while @@FETCH_STATUS= 0

begin

 fetch next from my_Cursor into @eventID

 update EventRule set ID = @Id where EventCode= @eventID

 

 set @Id = @Id + 1

end

 

close my_Cursor

deallocate my_Cursor

  相关解决方案