MySQL更新触发器错误

时间:2012-02-01 12:07:29

标签: mysql

我正在尝试在MySQL社区服务器5.5.16中创建更新触发器但我收到了错误:

ERROR 1064 (42000): 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 'REFER
ENCING NEW TABLE AS ntable
BEGIN atomic
        DECLARE n_overdraft INTEGER;
        DECL' at line 1

任何人都可以帮我解决这个问题。谢谢。 这是我的代码:

CREATE TABLE overdraft(account_no INTEGER,over_draft INTEGER);

DELIMETER //
CREATE TRIGGER t_creditexceed AFTER UPDATE ON Account REFERENCING NEW TABLE AS ntable
BEGIN atomic
    DECLARE n_overdraft INTEGER;
    DECLARE n_balance INTEGER;
    DECLARE n_number INTEGER;
    DECLARE n_credit INTEGER;
    DECLARE credit_exception condition for SQLSTATE '07030';

    SELECT balance, credit, number INTO n_balance, n_credit, n_number
    FROM ntable;
    IF ((n_balance < (-n_credit)) AND (n_balance >= 1.1 * (-n_credit)))
    THEN
    SET n_overdraft = n_balance + n_credit;
    INSERT INTO overdraft (account_no, over_draft) VALUES (n_number, n_overdraft);
    END IF;
    IF (n_balance < 1.1 *(- n_credit))
    THEN signal credit_exception;
    END IF;
END;
//

1 个答案:

答案 0 :(得分:0)

只需要删除REFERENCING NEW TABLE AS ntableatomic,因为它不是MySQL服务器标准。