How to fix this MySQL trigger?

前端 未结 2 1307
温柔的废话
温柔的废话 2021-01-26 00:37

I\'m trying to get this trigger to work:

CREATE TRIGGER Transaction_insert BEFORE INSERT ON Transaction
FOR EACH ROW WHERE Number = NEW.AccountNumber 
IF Account         


        
2条回答
  •  清歌不尽
    2021-01-26 01:12

    Your IF needs to be a full SELECT to reference another table (Account)

    IF EXISTS (SELECT * FROM `Account` A
                WHERE A.CreditBalance + NEW.Amount < A.CreditLimit AND 
                       A.Number = NEW.AccountNumber) THEN
       UPDATE ...
    

    Edit: this was on your 2nd duplicate answer

    In this case, remove the WHERE after FOR EACH ROW

提交回复
热议问题