declare @a varchar(100),@b varchar(100) declare user_cursor cursor for select a,b from tableA tab open user_cursor fetch next from user_cursor into @a,@b while @@fetch_status=0 begin update tableA set a=@a where b=@b fetch next from user_cursor into @a,@b end CLOSE user_cursor DEALLOCATE user_cursor
/*游标的使用*/ --定以后直接赋值-- declare test_Cursor Cursor GLOBAL for/*全局游标*/ select*from dbo.tab1 --先定义后赋值-- declare @test_Cursor2 cursor LOCAL for/*局部游标*/ set @test_Cursor2=Cursor for select*from dbo.tb2 --用GO结束上面的作用域-- go open text_Cursor open text_Cursor2