I am trying to create an update trigger in MySQL Community Server 5.5.16 but I have got an error:
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
Could anyone help me with this problem. Thanks.
Here is my code:
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;
//
Just needed to delete
REFERENCING NEW TABLE AS ntableandatomicbecause it’s not MySQL Server standard.