我已经在MySQL中编写了一个小的触发函数。这是我编写的触发器查询,未检查条件,直接分配了created_id的默认值。
CREATE TRIGGER `complain_attend_log` AFTER INSERT ON `attend_complain`
FOR EACH ROW BEGIN
DECLARE attend_created INT;
DECLARE created_id INT default 5;
SET attend_created = (SELECT attend_created FROM allotments WHERE complain_id = NEW.complain_id);
IF(attend_created = 1) THEN
SET created_id = 6;
END IF;
INSERT INTO complain_logs
VALUES(null,NEW.complain_id,NEW.allotment_id,NEW.attend_complain_id,NEW.is_closed,created_id,1,now(),1,now());
END