如何在phpmyadmin中创建MySQL触发器 [英] How to create a MySQL trigger in phpmyadmin
本文介绍了如何在phpmyadmin中创建MySQL触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在MySQL中创建一个触发器.我运行以下命令:
I want to create a trigger in MySQL. I run following commands:
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)
但是当我在phpmyadmin中运行以上SQL时,出现此错误:
But when I run above SQL in phpmyadmin I get this error:
#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?
推荐答案
这是由于未像通过CLI那样临时更改定界符引起的.尝试之一:
This is caused by not changing the delimiters temporarily as you did via CLI. Try either:
CREATE TRIGGER before_insert_money BEFORE INSERT ON money
FOR EACH ROW UPDATE accounts SET balance=10.0;
或
delimiter //
CREATE TRIGGER before_insert_money BEFORE INSERT ON money
FOR EACH
ROW
BEGIN
UPDATE accounts SET balance=10.0;
END;
//
delimiter ;