sqlserver中触发器+游标操作实现
代码如下:
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
相关推荐
lt云飞扬gt 2020-04-21
zycchun 2020-10-16
liuyang000 2020-09-25
ztyzly00 2020-07-21
talkingDB 2020-06-12
Smileyou 2020-06-07
chibangyuxun 2020-06-07
LuoXinLoves 2020-06-06
sifeimeng 2020-05-14
世樹 2020-04-10
fsl 2020-04-29
Justdoit00 2020-04-26
lt云飞扬gt 2020-04-25
流云追风 2020-04-22
bcbeer 2020-04-16
yuanshuai 2020-03-06
talkingDB 2020-02-22