2011-09-13

TSQL - Record edit tracking trigger


CREATE
      TRIGGER dbo.tTable1RecordEdit
      ON dbo.Table1
      FOR UPDATE
AS
BEGIN

      -- Refresh Record Edit tracking fields
      IF UPDATE(Field1)
            UPDATE
                  T
            set
                  T.RecordEditTimestamp = GETDATE()
                  , T.RecordEditUserID = suser_sname()
            from
                  Table1 as T
                  inner join
                  inserted as S
                  on
                  T.RecordID = S.RecordID
            ;
END

No comments:

Post a Comment