sqlserver 触发器 mysql_SQLServer触发器实例
以前沒寫過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
本文原創發布php中文網,轉載請注明出處,感謝您的尊重!
總結
以上是生活随笔為你收集整理的sqlserver 触发器 mysql_SQLServer触发器实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: UEditor ASP.NET 版使用教
- 下一篇: 【软件安装】CuteFTP Pro安装过