我正在尝试在触发器上有条件地更改值,但我遇到了错误。
我的触发器是:
CREATE TRIGGER `defineBase` BEFORE INSERT ON `perguntas`
FOR EACH ROW
BEGIN
IF NEW.per_base = 0 THEN
SET NEW.per_base = (SELECT per_id FROM perguntas ORDER BY per_id DESC LIMIT 1) + 1;
END IF;
END;
但不起作用。
答案 0 :(得分:0)
您需要将分隔符更改为;
以外的其他分隔符。否则,触发器定义将在第一个;
delimiter |
CREATE TRIGGER `defineBase` BEFORE INSERT ON `perguntas`
FOR EACH ROW
BEGIN
IF NEW.per_base = 0 THEN
SET NEW.per_base = (SELECT per_id FROM perguntas ORDER BY per_id DESC LIMIT 1) + 1;
END IF;
END
|
delimiter ;