【问题标题】:Can't create a trigger into PHPMyAdmin无法在 PHPMyAdmin 中创建触发器
【发布时间】:2017-08-27 06:04:09
【问题描述】:

我只想为我的 phpmyadmin 创建一个触发器。基本上,预期的功能是每当我更新财务表的信用列时,每一行的余额列都会自动更新。

我的程序是:

    CREATE TRIGGER UPDATE_BALANCE AFTER UPDATE financeofstudents
    FOR EACH ROW
    BEGIN
    IF financeofstudents.credit > 0 
    AND
    financeofstudents.credit <= financeofstudents.debit
    THEN
    UPDATE financeofstudents SET financeofstudents.balance = financeofstudents.debit-    financeofstudents.credit;
    END IF;
    END

但它给了我这个错误:

    Error

SQL query:

CREATE TRIGGER UPDATE_BALANCE AFTER UPDATE financeofstudents
FOR EACH ROW
BEGIN
IF financeofstudents.credit > 0 
AND
financeofstudents.credit <= financeofstudents.debit
THEN
UPDATE financeofstudents SET financeofstudents.balance = financeofstudents.debit-financeofstudents.credit

MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'financeofstudents
FOR EACH ROW
BEGIN
IF financeofstudents.credit > 0
AND
f' at line 1

我不知道问题出在哪里。各位高手,请帮帮我。

【问题讨论】:

    标签: mysql stored-procedures triggers dml


    【解决方案1】:

    错误消息在这里是一个有用的提示。它说 .. 在'some text from your query starting with the first thing it didn't understand'附近使用正确的语法

    在您的情况下,您需要在表名称前加上 ON 一词。

    CREATE TRIGGER update_balance 
           AFTER UPDATE
           ON financeofstudents
    
    FOR EACH ROW
    

    如果您观察到 MySQL 错误消息难以解释,那么您是正确的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-22
      • 2018-03-04
      • 1970-01-01
      • 2015-10-14
      • 2013-07-26
      • 1970-01-01
      • 2016-10-03
      相关资源
      最近更新 更多