当前位置: 移动技术网 > IT编程>数据库>MSSQL > sqlserver中触发器+游标操作实现

sqlserver中触发器+游标操作实现

2017年12月12日  | 移动技术网IT编程  | 我要评论

小青龙汤歌诀,wep 破解,蔡顶伦

复制代码 代码如下:

create trigger tri_wk_csvhead_history on wk_csvhead_history
--声明一个tri_wk_csvhead_history触发器,
instead of insert ---插入操作被代替执行下面的操作
as
begin
declare yb cursor --声明一个游标
for
 select noteno from inserted--这里的noteno要和下面的匹配
 open yb
  declare @noteno varchar(50)--这里的noteno要和上面的匹配,定义一个游标变量@noteno,用来操作insered表中的noteno.
  fetch next from yb into @noteno--这里的noteno要是上面的匹配,移动游标
  while(@@fetch_status=0)--0操作成功,-1 fetch 语句失败或此行不在结果集中,-2 被提取的行不存在
  begin
  delete from wk_csvdetail_history where noteno=@noteno
   delete from wk_csvhead_history where noteno=@noteno
  fetch next from yb into @noteno --继续移动游标,直到@@fetch_status不等于时.
   end
close yb --关闭游标
deallocate yb --释放游标
insert into wk_csvhead_history select * from inserted
end

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网