Skip to content

Instantly share code, notes, and snippets.

@robjshaw
Last active December 14, 2015 04:09
Show Gist options
  • Select an option

  • Save robjshaw/5026531 to your computer and use it in GitHub Desktop.

Select an option

Save robjshaw/5026531 to your computer and use it in GitHub Desktop.
mysql trigger - action time: before / event: update
/* logging example */
BEGIN
IF new.status <> old.status
THEN
INSERT INTO pstatus_log(dtCreated, statusOld, statusNew, fkid)
VALUES (now(), old.status, new.status, new.fkid);
END IF;
END
/* update DateTimeUpdated whenever the row is changed. */
BEGIN
SET NEW.DateTimeUpdated = NOW();
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment