Dict.CN 在线词典, 英语学习, 在线翻译 ------------- MyGitee 朱秋贵内科诊所 My腾云code

游标-批量修改

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
posted @ 2009-12-04 10:55  cn2024  阅读(184)  评论(0编辑  收藏  举报