如何在触发器操作中使用WHEN条件

时间:2020-01-05 05:29:06

标签: mysql database-trigger

当Ac_holders表中的余额小于零时,我想从Ac_holders中插入数据以借出。并喜欢将负值更新为正值并插入贷款表中的金额。 并先谢谢您。

mysql> create trigger Triggeroverdraft after insert on Ac_holders
   -> for each row when balance<0
   -> begin
   ->  insert into loan(id, name,amonut) values (new.id, new.name, new.amount);
   -> end``` 

1 个答案:

答案 0 :(得分:0)

正式:

CREATE TRIGGER Triggeroverdraft 
AFTER INSERT 
ON Ac_holders
FOR EACH ROW 
INSERT INTO loan(id, name, amount) 
    SELECT new.id, new.name, new.amount
    WHERE ???.balance < 0;              -- NEW.balance ?