if语句在mysql触发器定义中

时间:2012-07-22 15:21:37

标签: mysql triggers

我在以下代码中收到错误。

CREATE TRIGGER au_auction AFTER UPDATE ON dmtable 
    FOR EACH ROW
    BEGIN
        IF NEW.bid > OLD.bid THEN
            INSERT INTO auction_log(auction,id,ts,item,bid) VALUES('update',NEW.id,NEW.ts,NEW.item,NEW.bid);
        END IF;

    END;

问题出在语法层面......你能不能给出更多的光?

这是错误消息:

Error Code: 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 5

MySql 5.x

谢谢

1 个答案:

答案 0 :(得分:1)

DELIMITER //
CREATE TRIGGER au_auction AFTER UPDATE ON dmtable 
    FOR EACH ROW
    BEGIN
        IF NEW.bid > OLD.bid THEN
            INSERT INTO auction_log(auction,id,ts,item,bid)
                           VALUES('update', NEW.id, NEW.ts, NEW.item, NEW.bid);
        END IF;

    END//
DELIMITER ;

阅读documentation about creating triggers,示例很有用。