Skip to content

Instantly share code, notes, and snippets.

@faogustavo
Created June 30, 2016 01:37
Show Gist options
  • Save faogustavo/6ddf23faa7a306382528c4177e8fcc1c to your computer and use it in GitHub Desktop.
Save faogustavo/6ddf23faa7a306382528c4177e8fcc1c to your computer and use it in GitHub Desktop.
DROP TRIGGER IF EXISTS `t_demissao`;
DELIMITER $$
CREATE TRIGGER t_demissao BEFORE UPDATE
ON user
FOR EACH ROW
BEGIN
IF NEW.state = 'I' THEN
SET NEW.resignation_date = NOW();
UPDATE equipament_has_user ehu
SET ehu.state = 'I' WHERE ehu.user_id = NEW.id;
END IF;
END$$
DELIMITER ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment