日期:2014-05-17 浏览次数:20460 次
CREATE TRIGGER PURTD20121123 ON [dbo].[PURTC]
FOR INSERT
AS
DECLARE @TC001 CHAR(4),
@TC002 CHAR(11),
@TD001 CHAR(4),
@TD002 CHAR(11),
@TCD01 CHAR(1)
BEGIN TRANSACTION
SET NOCOUNT ON
SELECT @TC001=TC001,@TC002=TC002,@TCD01=TCD01 FROM INSERTED
SELECT @TD001=TD001,@TD001=TD001,@TD002=TD002 FROM PURTD WHERE TD001=@TC001 AND TD002=@TC002
IF UPDATE(TCD01) AND @TCD01='Y'
BEGIN
UPDATE PURTD SET TD016='y' WHERE TD001=@TC001 AND TD002=@TC002 AND TD018='Y' AND TD016='N'
END
SET NOCOUNT OFF
COMMIT TRANSACTION
CREATE TRIGGER PURTD20121123 ON [dbo].[PURTC]
FOR UPDATE
AS
BEGIN TRANSACTION
SET NOCOUNT ON
UPDATE PURTD SET TD016='y'
FROM INSERTED i
WHERE TD001=i.TC001 AND TD002=i.TC002 AND i.TD018='Y' AND i.TD016='N'
END
SET NOCOUNT OFF
COMMIT TRANSACTION
你这个应该是Update触发器
update tb
set tb.字段=i.字段 from inserted where i.关联字段=tb.关联字段
ALTER TRIGGER PURTD20121123 ON [dbo].[PURTC]
FOR INSERT
AS
DECLARE @TC001 CHAR(4),
@TC002 CHAR(11),
@TD001 CHAR(4),
@TD002 CHAR(11),
@TCD01 CHAR(1)
BEGIN TRANSACTION
SET NOCOUNT ON
SELECT @TC001=TC001,@TC002=TC002,@TCD01=TCD01 FROM INSERTED
SELECT @TD001=TD001,@TD001=TD001,@TD002=TD002 FROM PURTD WHERE TD001=@TC001 AND TD002=@TC002