如何在phpmyadmin中创建MySQL触发器

前端之家收集整理的这篇文章主要介绍了如何在phpmyadmin中创建MySQL触发器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在 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)

但是当我在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

这有什么不对?如何创建触发器?

这是因为您没有像通过CLI那样暂时更改分隔符.尝试:
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 ;

见:This questionthis question.

猜你在找的PHP相关文章