Skip to content

Instantly share code, notes, and snippets.

@jetstreamin
Last active January 27, 2019 20:34
Show Gist options
  • Save jetstreamin/30afeae7706ffad1476942915e80ceb4 to your computer and use it in GitHub Desktop.
Save jetstreamin/30afeae7706ffad1476942915e80ceb4 to your computer and use it in GitHub Desktop.
SQL - Row Update Trigger
-- Add the Modified field to the row
-- E.g. Add a column to the table using a create/alter statement like:
-- ...
-- Modified DATETIME2(3),
-- ...
-- Then create the trigger
CREATE TRIGGER updateModified
ON dbo.YourTable
AFTER UPDATE
AS
UPDATE dbo.YourTable
SET modified = SYSDATETIME()
FROM Inserted i
WHERE dbo.YourTable.PrimaryKey = i.PrimaryKey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment