首页 > 数据库 > mysql教程 > SQLServer触发器实例

SQLServer触发器实例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
发布: 2016-06-07 15:33:25
原创
1403 人浏览过

以前没写过SqlServer的触发器,折腾了一天,总算写好了,现在记录一下心得。 SqlServer触发器的语法就不提了,主要记录一下主要事项。每个开始都得有Begin 内容 end ,之前不明白这里,写条件触发折腾了好多遍都是不准确,以下是实例: if (object_id('inser

       以前没写过SqlServer的触发器,折腾了一天,总算写好了,现在记录一下心得。

       SqlServer触发器的语法就不提了,主要记录一下主要事项。每个开始都得有Begin  内容  end   ,之前不明白这里,写条件触发折腾了好多遍都是不准确,以下是实例:

     

      if (object_id('insert_black_list', 'tr') is not null)    drop trigger insert_black_list
go
create TRIGGER insert_black_list
    on User_Infor_Message
    after insert
    as
    declare @messagetype varchar(1)
    declare @cardno varchar(10)
    BEGIN
     select @messagetype = messagetype,@cardno=cardno from User_Infor_Message
     if @messagetype='1' or @messagetype='5'
         begin
           if (select count(cardno) from Balck_List where cardno=@cardno)=0
              begin
                insert into Balck_List select Inserted.cardno,Inserted.cardid,convert(varchar(8),getdate(),112) from Inserted
              end
         end
     else if @messagetype='6'
       begin
          delete from Balck_List where cardno=@cardno
       end
    END
 go

     

相关标签:
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
tp6连接sqlserver数据库问题
来自于 1970-01-01 08:00:00
0
0
0
php 怎样调用sqlserver的分页储存过程
来自于 1970-01-01 08:00:00
0
0
0
php 7.2.10 链接 SQLserver2008r2 报错
来自于 1970-01-01 08:00:00
0
0
0
Laravel 中无法连接 SQL Server
来自于 1970-01-01 08:00:00
0
0
0
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板