开发者

What's wrong with my MYSQL trigger syntax?

开发者 https://www.devze.com 2023-02-04 06:34 出处:网络
CREATE TRIGGER event_house_dealed AFTER UPDATE ON house FOR EACH ROW BEGIN DECLARE finished IN开发者_开发问答T;
CREATE TRIGGER event_house_dealed AFTER UPDATE ON house FOR EACH ROW 
BEGIN
DECLARE finished IN开发者_开发问答T;
IF NEW.isdeal = 1 THEN
    SET finished = 1;
END IF;
END;

The MySQL server keep saying

SQL Error (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 'IF NEW.isdeal = 1 THEN SET finished = 1' at line 1

Thanks.


You need to change delimiter before defining trigger

DELIMITER ||
CREATE TRIGGER event_house_dealed AFTER UPDATE ON house FOR EACH ROW 
BEGIN
DECLARE finished INT;
IF NEW.isdeal = 1 THEN
    SET finished = 1;
END IF;
END||

Then of course change the delimiter back to ;

DELIMITER ;

Same goes for declaring functions and stored procedures

0

精彩评论

暂无评论...
验证码 换一张
取 消