如何在 phpmyadmin 中创建 MySQL 触发器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17869629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:18:28  来源:igfitidea点击:

How to create a MySQL trigger in phpmyadmin

mysqltriggersphpmyadmin

提问by Moein Hosseini

I want to create a trigger in MySQL. I run following commands:

我想在 MySQL 中创建一个触发器。我运行以下命令:

mysql> delimiter //
mysql> CREATE TRIGGER before_insert_money BEFORE INSERT ON money
    -> FOR EACH ROW
    -> BEGIN
    -> UPDATE accounts SET balance=10.0;
    -> END;
    -> //
Query OK, 0 rows affected (0.19 sec)

But when I run above SQL in phpmyadmin I get this error:

但是当我在 phpmyadmin 中运行高于 SQL 时,我收到此错误:

#1064 - 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 '' at line 4 

what's wrong here? How do I create a trigger?

这里有什么问题?如何创建触发器?

回答by Brainless Box

This is caused by not changing the delimiters temporarily as you did via CLI. Try either:

这是由于没有像通过 CLI 那样临时更改分隔符造成的。尝试:

CREATE TRIGGER before_insert_money BEFORE INSERT ON money
FOR EACH ROW UPDATE accounts SET balance=10.0;

or

或者

delimiter //
CREATE TRIGGER before_insert_money BEFORE INSERT ON money
FOR EACH
ROW
BEGIN
    UPDATE accounts SET balance=10.0;
END;
//
delimiter ;

See: This questionand this question.

请参阅:这个问题这个问题