触发器的使用

时间:2016-04-20 21:57:40   收藏:0   阅读:250

ALTER TRIGGER [dbo].[IsFull] ON [dbo].[BorrowBid] 
FOR UPDATE
AS
declare @AlsoNeedAmount decimal(18,2)
declare @GurantFlag int
declare @AlsoNeedGurantAmount decimal(18,2)

select  @AlsoNeedAmount=AlsoNeedAmount,@GurantFlag=GurantFlag,@AlsoNeedGurantAmount=AlsoNeedGurantAmount from BorrowBid where BorrowBidID=(select BorrowBidID from inserted)
if(@GurantFlag=1)--担保标
    begin
        if(@AlsoNeedAmount=0 and @AlsoNeedGurantAmount=0)
           update BorrowBid set  FullFlag=1 where BorrowBidID=(select BorrowBidID from inserted)
    end
else--非担保标
    begin
  if(@AlsoNeedAmount=0)
     update BorrowBid set  FullFlag=1 where BorrowBidID=(select BorrowBidID from inserted)
    end

--inserted,deleted是在触发器中使用的两个临时表,
--当执行insert操作时,在inserted中存储着当前插入的记录,

在执行delete操作时,在deleted中存储着当前删除的记录,

当执行update时,在inserted中存储着修改后的记录,在deleted中存储着修改前的记录。

原文:http://www.cnblogs.com/xinhuawei/p/5414481.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!