sqlserver中触发器+游标操作实现
时间:2024-01-20 19:25:42
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
标签:SQL触发器,游标
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python中常用的os操作汇总
2022-12-13 08:30:16
![](https://img.aspxhome.com/file/2023/2/75302_0s.png)
JavaScript日期工具类DateUtils定义与用法示例
2024-04-16 08:51:29
![](https://img.aspxhome.com/file/2023/3/136833_0s.png)
asp下过滤非法的SQL字符的函数代码
2011-03-03 11:23:00
Excel VBA连接并操作Oracle
2009-08-08 22:58:00
如何利用python将Xmind用例转为Excel用例
2022-06-18 19:18:46
![](https://img.aspxhome.com/file/2023/2/133562_0s.png)
Python的进制转换和ASCLL转换你了解吗
2021-09-18 05:33:59
Python过滤掉numpy.array中非nan数据实例
2021-08-25 14:47:44
使用Python的Flask框架构建大型Web应用程序的结构示例
2022-05-01 01:35:35
PHP合并两个或多个数组的方法
2023-06-11 12:06:28
![](https://img.aspxhome.com/file/2023/6/55286_0s.jpg)
Windows10下mysql 5.7.21 Installer版安装图文教程
2024-01-18 10:52:23
![](https://img.aspxhome.com/file/2023/0/69150_0s.png)
Python学习之流程控制与条件判断总结
2023-08-20 13:37:02
![](https://img.aspxhome.com/file/2023/8/70148_0s.jpg)
Python WEB应用部署的实现方法
2022-02-18 07:34:35
![](https://img.aspxhome.com/file/2023/7/127687_0s.png)
Python双端队列deque的实现
2022-07-07 02:37:29
![](https://img.aspxhome.com/file/2023/2/71552_0s.png)
使用Python脚本对Linux服务器进行监控的教程
2022-06-19 18:27:26
![](https://img.aspxhome.com/file/2023/1/109631_0s.jpg)
PHP bin2hex()函数基础实例讲解
2023-06-12 16:30:44
![](https://img.aspxhome.com/file/2023/7/55397_0s.png)
ASP 游标参数详解(ASP记录集)第1/2页
2011-04-08 11:04:00
python+selenium 实现扫码免密登录示例代码
2021-02-03 06:41:57
python中bottle使用实例代码
2023-07-03 14:21:15
![](https://img.aspxhome.com/file/2023/9/105809_0s.png)
js实现黑色简易的滑动门网页tab选项卡效果
2024-04-23 09:05:53
![](https://img.aspxhome.com/file/2023/9/135939_0s.jpg)
php通过exif_read_data函数获取图片的exif信息
2023-10-27 09:01:44