Skip to content

Instantly share code, notes, and snippets.

@joeriks
Created December 4, 2013 14:24
Show Gist options
  • Select an option

  • Save joeriks/7788225 to your computer and use it in GitHub Desktop.

Select an option

Save joeriks/7788225 to your computer and use it in GitHub Desktop.
sql trigger - revert value if condition is met
ALTER TRIGGER reset_deleted
ON mytable
AFTER update
AS
IF (SELECT count(*) FROM inserted WHERE [type]='sometype' AND [deleted]=1)>0
BEGIN
SET NOCOUNT ON;
UPDATE mytable SET [deleted]=0 WHERE id in (SELECT id FROM inserted WHERE [type]='sometype' AND [deleted]=1)
END
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment