游标是个好东西,最大的用处在于可以将表中的数据全部取出来,修改了再存进去。
--先定义两个变量用来保存取出的数据 declare @id int declare @name nvarchar(20) declare cursor1 cursor for ---定义游标cursorl select ID, Name from Test.dbo.Emp ---使用游标对象 open cursorl1 ---打开游标 fench next from cursor1 into @id , @name ---将游标向下移一行,将数据存入变量中 while @@fench_status = 0 begin update Test.dbo.Emp set Name = name + "hello world" where ID = @id fench next from cursor1 into @id, @name end close cursor1