当我尝试在表中插入新行时,我的触发器失败,因为 Mysql 不支持更新触发器分配到的同一表中的行。有人对好的解决方法/替代方案有建议吗?
我的触发器:
-- Trigger DDL Statements
DELIMITER $$
CREATE TRIGGER check_sequence
BEFORE INSERT ON data FOR EACH ROW
BEGIN
IF EXISTS(SELECT TRUE FROM data WHERE sequence = NEW.sequence) THEN
UPDATE data SET sequence=sequence+1 WHERE sequence >= NEW.sequence;
END IF;
END $$
DELIMITER ;
尝试插入新行时显示的错误 Sql:
ERROR 1442 (HY000): Can't update table 'data' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
谢谢解答,