I use this trigger to track the last update or insert for a record.
Here’s how I create the trigger.
- Add a “Last_Modified” column with data type “datetime” to the table.
- Create a new SQL query in the SQL Server Management Studio.
- Paste the following code into the SQL query.
CREATE TRIGGER dbo.MyTable ON MyTable FOR UPDATE, INSERT AS UPDATE dbo.MyTable SET Last_Modified = CURRENT_TIMESTAMP WHERE PKeyColumnName IN (SELECT PKeyColumnName FROM inserted);