触发器的使用

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中存储着修改前的记录。

posted on 2012-04-28 15:10  hanshuhe  阅读(178)  评论(0编辑  收藏  举报