我正在尝试触发,以便在插入新记录后插入新行。
看起来像这样:
DELIMITER $$
DROP TRIGGER IF EXISTS insertOcupacioLlorer$$
CREATE TRIGGER insertOcupacioLlorer BEFORE INSERT ON OCUPACIO
FOR EACH ROW
BEGIN
IF NEW.OCU_codiCasa = 'A0325IGM05' THEN
INSERT INTO OCUPACIO(OCU_codiCasa,OCU_dataInici,OCU_dataFi,OCU_tipus,OCU_idReserva,OCU_dataBloqueig)
VALUES
('A0323IGM05',NEW.OCU_dataInici,NEW.OCU_dataFi,NEW.OCU_tipus,NEW.OCU_idReserva,NEW.OCU_dataBloqueig);
END IF;
IF NEW.OCU_codiCasa = 'A0323IGM05' THEN
INSERT INTO OCUPACIO(OCU_codiCasa,OCU_dataInici,OCU_dataFi,OCU_tipus,OCU_idReserva,OCU_dataBloqueig)
VALUES
('A0325IGM05',NEW.OCU_dataInici,NEW.OCU_dataFi,NEW.OCU_tipus,NEW.OCU_idReserva,NEW.OCU_dataBloqueig);
END IF;
END;$$
DELIMITER ;
当我插入新记录时,我得到了
#1442 - Can't update table 'OCUPACIO' in stored function/trigger because it is already used by statement which invoked this stored function/trigger
嗯,我想触发器可能会再次调用自己,这会产生错误。
如果我无法用触发器达到我想要的效果,还有另一种方法吗?
感谢。