13 November 2012

After UPDATE Trigger For Same Table


USE [Testdb]
GO
/****** Object:  Trigger [dbo].[UpdatePart]    Script Date: 11/13/2012 15:24:04 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[UpdatePart]
ON [dbo].[Parts]
FOR INSERT, UPDATE
AS
BEGIN
    DECLARE @Id int

    SET @Id = (SELECT id FROM inserted ins)
   
    IF (@Id != 0)
    BEGIN
        UPDATE Parts
        SET
            Date= getdate()
        WHERE
            Id = (SELECT ins.Id FROM inserted ins)
    END
END