sqlserver2000的触发器如何建立(100分)

  • 主题发起人 主题发起人 希诺
  • 开始时间 开始时间

希诺

Unregistered / Unconfirmed
GUEST, unregistred user!
我想做一个触发器 目的是当一个表中有一列的值被更新为1 的时候
向另一个表中插入数据 是针对sqlserver2000的 不知道如何写语法

在oracle中 针对可以用:new 和 :old 表示
在sqlserver2000中用什么表示??
 
在sqlserver中用INSERTED和deleted,不区分大小写的。下面是两个例子。

CREATE TRIGGER dbo.AccountingRepTrigger1 ON dbo.AccountingRep
FOR UPDATE AS
IF Update(amtUpdated)
begin
declare @a1 float
declare @a2 float
select @a1=(select amtUpdated from Inserted)
select @a2=(select amtUpdated from deleted)

update accountingRep
set balance=balance + @a1 - @a2
where tableCode=(select tableCode from deleted)
and tableNo=(select tableNo from deleted)
end

CREATE TRIGGER [trgAtoComplete] ON dbo.TpcTPreMatMaster
FOR UPDATE
AS
IF Update(status)
BEGIN
declare @instNo char(10)
declare @items tinyint
declare @recType char(1)
declare @status char(1)
declare @colorNo smallint
select @instNo=instNo,@items=items,
@recType=recType,@status=status,
@colorNo=colorNo from INSERTED
IF @status='D'
BEGIN --删除细档
update TpcTPreMatMDetail
set status = 'D'
where instNo = @instNo
and items=@items
and colorNo=@colorNo
AND recType=@recType
return
END

IF @status<>'Y'
return

--如果存在其它颜色还有'N'状态的,则退出
IF EXISTS
(SELECT * FROM TpcTPreMatMaster
WHERE instNo=@instNo
AND items=@items
AND recType=@recType
AND status='N')
return
--如果存在其它颜色还有'N'状态的,则退出

IF (@recType='V')
BEGIN
update TpcTPreMatDetail
set vampLack = 'Y'
where instNo = @instNo
and items=@items
AND status<>'D'

END
ELSE IF (@recType='B')
BEGIN
update TpcTPreMatDetail
set bigSoleLack = 'Y'
where instNo = @instNo
and items=@items
AND status<>'D'
END
ELSE IF (@recType='M')
BEGIN
update TpcTPreMatDetail
set midSoleLack = 'Y'
where instNo = @instNo
and items=@items
AND status<>'D'
END
ELSE IF (@recType='L')
BEGIN
update TpcTPreMatDetail
set lastLack = 'Y'
where instNo = @instNo
and items=@items
AND status<>'D'
END
END

 
后退
顶部