T-SQL Trigger Update

后端 未结 3 1502
暗喜
暗喜 2020-12-16 12:56

I have a table with 3 fields [ID, Name, LastUpdated].
LastUpdated has a default value of \"GetDate() so it automatically fills itself when a new record is added.

3条回答
  •  借酒劲吻你
    2020-12-16 13:43

    CREATE TRIGGER dbo.refreshModifyDate 
          ON  tStoreCategoriesImages
          FOR INSERT, UPDATE
    AS 
      BEGIN
        SET NOCOUNT ON;
            update t set t.ModifyDate = getdate() from tStoreCategoriesImages t 
            inner join inserted i on i.ID = t.ID
      END
    GO
    

提交回复
热议问题