1:用游标实现批量修改数据
原理:1:请出一个表中的数据放在游标的临时表中,
2:fetch next from testcur info 来循环表中的每条数据
3:对每条数据进行修改 或者 删除操作

create table test
(
iId int identity(1,1) primary key,
tag nvarchar(10),
state1 nvarchar(10),
state2 nvarchar(10),
state3 nvarchar(10),
state4 nvarchar(10)
)
declare @tempid int
declare @temptag nvarchar(10)
declare testcur cursor for select iId, tag from test
open testcur
fetch next from testcur into @tempid, @temptag
while @@FETCH_STATUS=0 -- 0 = 语句执行成功 -1 = 语句失败或此句不在结果集中 -2 = 被提取的行不存在
begin
print @@FETCH_STATUS
fetch next from testcur into @tempid, @temptag
end
close testcur
deallocate testcur
(
iId int identity(1,1) primary key,
tag nvarchar(10),
state1 nvarchar(10),
state2 nvarchar(10),
state3 nvarchar(10),
state4 nvarchar(10)
)
declare @tempid int
declare @temptag nvarchar(10)
declare testcur cursor for select iId, tag from test
open testcur
fetch next from testcur into @tempid, @temptag
while @@FETCH_STATUS=0 -- 0 = 语句执行成功 -1 = 语句失败或此句不在结果集中 -2 = 被提取的行不存在
begin
print @@FETCH_STATUS
fetch next from testcur into @tempid, @temptag
end
close testcur
deallocate testcur