触发器操作:在触发器中嵌套多个游标

 1 None.gif if   exists ( select  name  from  sysobjects  where  name = ' Insert_PicType_T07_Trig '   and  type = ' TR ' )
 2 None.gif DROP   TRIGGER  Insert_PicType_T07_Trig
 3 None.gif go
 4 None.gif
 5 None.gif CREATE   TRIGGER  Insert_PicType_T07_Trig  ON   PicType_T07
 6 None.gif FOR   INSERT  
 7 None.gif AS
 8 None.gif BEGIN
 9 None.gif    print   ' 开始响应 '
10 None.gif    DECLARE   @PicType_id   int , @PicRightsType_id   bigint         -- 图片类型ID,更新浏览图片权限类型ID
11 None.gif     DECLARE  PicTypeId_cursor  CURSOR   FOR  
12 None.gif      SELECT   RT07F01
13 None.gif      FROM  INSERTED
14 None.gif    OPEN  PicTypeId_cursor
15 None.gif    FETCH   NEXT   FROM  PicTypeId_cursor 
16 None.gif    INTO   @PicType_id
17 None.gif    WHILE   @@FETCH_STATUS   =   0
18 None.gif  BEGIN
19 None.gif    --  声明嵌套的游标
20 None.gif     --  从嵌套的游标取出另一个表(PicRightsType)的不重复的权限类型ID
21 None.gif     DECLARE  PicRightsTypeID_cursor  CURSOR   FOR  
22 None.gif    SELECT   distinct (RT16F01)
23 None.gif    FROM    PicRightsType_T16
24 None.gif    -- 打开游标
25 None.gif     OPEN  PicRightsTypeID_cursor
26 None.gif    FETCH   NEXT   FROM  PicRightsTypeID_cursor  INTO   @PicRightsType_id
27 None.gif    IF   @@FETCH_STATUS   <>   0  
28 None.gif       PRINT   ' No ID '      
29 None.gif    WHILE   @@FETCH_STATUS   =   0
30 None.gif    BEGIN
31 None.gif       INSERT   INTO  PicRightsType_T16(RT16F01,RT16F02)  VALUES ( @PicRightsType_id , @PicType_id )
32 None.gif       FETCH   NEXT   FROM  PicRightsTypeID_cursor  INTO   @PicRightsType_id
33 None.gif    END
34 None.gif    CLOSE  PicRightsTypeID_cursor
35 None.gif    DEALLOCATE  PicRightsTypeID_cursor
36 None.gif   
37 None.gif    --  Get the next PicTypeId.
38 None.gif     FETCH   NEXT   FROM  PicTypeId_cursor 
39 None.gif    INTO   @PicType_id
40 None.gif  END
41 None.gif  CLOSE  PicTypeId_cursor 
42 None.gif  DEALLOCATE  PicTypeId_cursor 
43 None.gif END
44 None.gif GO
45 None.gif
46 None.gif
47 None.gif -- INSERT INTO PICTYPE_T07(RT07F02,RT07F03)VALUES('frj照片','1')   
48 None.gif
49 None.gif
1 None.gif CREATE   TRIGGER  CheckDate4  ON  cardtype_t11
2 None.gif FOR   update
3 None.gif AS
4 None.gif begin
5 None.gif print   ' hao '
6 None.gif SELECT   *   FROM  inserted
7 None.gif ROLLBACK    // 回滚刚才的操作
8 None.gif end
9 None.gif drop   trigger  CheckDate4
posted on 2005-12-09 12:49 DotNet编程 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/furenjun/archive/2005/12/09/293694.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值