如何使用TRIGGER在MYSQL中自动更新表

时间:2012-03-01 05:03:53

标签: mysql triggers

我在mysql数据库中有一个表格,我根据利息+借入的数量来计算New Owed Balcance ...我希望它是当利息被改变时新欠的balace改变我使用触发器但它确实当兴趣改变时似乎没有更新它

DELIMITER |

CREATE TRIGGER updateloan BEFORE INSERT ON loan
  FOR EACH ROW BEGIN
    SET NEW.app_amnt_owed = NEW.app_intrst +NEW. app_ln_amnt;
  END;
|

1 个答案:

答案 0 :(得分:1)

CREATE TRIGGER updateloan_update
  BEFORE UPDATE ON loan
  FOR EACH ROW
  SET NEW.app_amnt_owed = NEW.app_intrst + NEW.app_ln_amnt;