工作时用到触发器要支持sqlserver 写的Demo 纪念下

工作时用到触发器要支持sqlserver 写的Demo 纪念下,第1张

概述学习连接: http://www.cnblogs.com/hoojo/archive/2011/07/20/2111316.html   Demo1:简单的触发器   CREATE TRIGGER D_EFILE1_0008_TRIGGER   ON D_EFILE1_0008  AFTER INSERT,DELETE  AS   declare @SYSCODE varchar(32), @UN 学习连接: http://www.cnblogs.com/hoojo/archive/2011/07/20/2111316.html   Demo1:简单的触发器   CREATE TRIGGER D_Efile1_0008_TRIGGER 
 ON D_Efile1_0008
 AFTER INSERT,DELETE
 AS
  declare @SYSCODE varchar(32),@UNITSYS varchar(32);
  if (exists (select 1 from inserted) and not exists (select 1 from deleted))
   BEGIN 
    select @SYSCODE = SYSCODE,@UNITSYS=UNITSYS from INSERTED;
    INSERT INTO INCtable VALUES(@SYSCODE,'1',2,@UNITSYS,convert(char(19),getdate(),20));
   END
  else if (not exists (select 1 from inserted) and exists (select 1 from deleted))
   BEGIN
    select @SYSCODE = SYSCODE,@UNITSYS=UNITSYS from deleted;
    INSERT INTO INCtable VALUES(@SYSCODE,1,20));
   END         Demo2:复杂点的触发器   CREATE TRIGGER D_file1_0008_TRIGGER ON D_file1_0008 FOR UPDATE AS   IF UPDATE(STATUS)      declare @SYSCODE varchar(32),@UNITSYS varchar(32),@STATUS INT,@ESYSCODE varchar(32);    begin     select @SYSCODE = SYSCODE,@UNITSYS=UNITSYS,@STATUS=STATUS from INSERTED;    end    DECLARE ESYSCODES CURSOR FOR  select SYSCODE from D_Efile1_0008  WHERE PSYSCODE=(select SYSCODE from INSERTED);    open ESYSCODES;    FETCH NEXT FROM ESYSCODES    INTO @ESYSCODE    WHILE @@FETCH_STATUS = 0     BEGIN      IF (@STATUS=1)       BEGIN        INSERT INTO INCtable VALUES(@ESYSCODE,20));       end      else if(@STATUS=0)       BEGIN         INSERT INTO INCtable VALUES(@ESYSCODE,20));       end       FETCH NEXT FROM ESYSCODES      INTO @ESYSCODE     END    CLOSE ESYSCODES;    DEALLOCATE ESYSCODES; 总结

以上是内存溢出为你收集整理的工作时用到触发器要支持sqlserver 写的Demo 纪念下全部内容,希望文章能够帮你解决工作时用到触发器要支持sqlserver 写的Demo 纪念下所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1169823.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存