记录更新后重新运行触发器

时间:2014-08-13 10:40:20

标签: mysql triggers

我创建了以下触发器。

CREATE DEFINER=`root`@`localhost` TRIGGER `SOS`.`auto_field`
BEFORE INSERT ON 
SOS.Tickets
FOR EACH ROW BEGIN
IF (NEW.DURATION = 0)THEN
SET NEW.DURATION = NULL;
END IF;
SET NEW.MONTH = SUBSTR(NEW.DAY, 1, 2);
SET NEW.JOUR = SUBSTR(NEW.DAY, 4, 2);
SET NEW.YEAR = SUBSTR(NEW.DAY, 7, 4);
IF (NEW.SEVERITY = 1)THEN
SET NEW.THRESHOLD = 240;
END IF;
IF (NEW.SEVERITY = 2)THEN
SET NEW.THRESHOLD = 480;
END IF;
IF (NEW.SEVERITY = 3)THEN
SET NEW.THRESHOLD = 10080;
END IF;
IF (NEW.SEVERITY = 4)THEN
SET NEW.THRESHOLD = 43200;
END IF;
SET NEW.WEEK = WEEK(STR_TO_DATE(NEW.DAY,'%m/%d/%Y'),1);
IF (NEW.DURATION > NEW.THRESHOLD)THEN
SET NEW.SLA_OUT = 'OUT';
END IF;
IF (NEW.DURATION != '')THEN
SET NEW.GLOBAL_HOUR_DURATION = NEW.DURATION/60;
END IF;
END

我需要的是,当我对旧记录进行更改时,它会再次运行,以便使用正确的值进行更新。

0 个答案:

没有答案