我想在mysql中添加触发器......
CREATE TRIGGER mytrigger BEFORE INSERT ON table_1
FOR EACH ROW
BEGIN SET
NEW.`order` = (SELECT 1 + COALESCE((SELECT MAX(`order`) FROM `table_1`), 0));
END
我总是得到错误:
Error
SQL query: Documentation
CREATE TRIGGER mytrigger BEFORE INSERT ON table_1
FOR EACH
ROW
BEGIN SET NEW.`order` = ( SELECT 1 + COALESCE( (
SELECT MAX( `order` )
FROM `table_1` ) , 0 )
);
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4
有什么想法吗?
答案 0 :(得分:1)
您需要更改分隔符。否则引擎认为该语句在第一个;
处完成。但这是错误的。
delimiter |
CREATE TRIGGER mytrigger BEFORE INSERT ON table_1
FOR EACH ROW
BEGIN
SET NEW.`order` = (SELECT 1 + COALESCE((SELECT MAX(`order`) FROM `table_1`), 0));
END
|
delimiter ;