简体   繁体   English

MySQL 5.7创建触发器语法错误?

[英]MySQL 5.7 Create Trigger Syntax Error?

I've been trying to create a simple BEFORE INSERT trigger on a database table (MySQL v 5.7 ) but I keep receiving a vague "#1064 ... syntax error" message which doesn't help resolve the issue. 我一直在尝试在数据库表(MySQL v 5.7)上创建一个简单的BEFORE INSERT触发器,但是我一直收到模糊的“#1064 ...语法错误”消息,这无助于解决问题。

Here's the SQL: 这是SQL:

CREATE OR REPLACE TRIGGER `CREATE_QUIZ_TRIG` BEFORE INSERT ON `quiz`
 FOR EACH ROW BEGIN
    SET NEW.ACTIVE = UPPER(NEW.ACTIVE);
    SET NEW.CREATED = NOW();
 END
/

All I'm trying to do is enforce a column to uppercase and then insert the current date & time into a timestamp column. 我要做的就是将一列强制为大写,然后将当前日期和时间插入时间戳列。 I've been following the documentation from: 我一直在关注以下文档:

https://dev.mysql.com/doc/refman/5.7/en/trigger-syntax.html https://dev.mysql.com/doc/refman/5.7/zh-CN/trigger-syntax.html

and realise that for multi-statement expression I have to redefine the delimiter at the beginning of the trigger's creation but the same '#1064' error occurs. 并意识到对于多语句表达式,我必须在触发器创建开始时重新定义定界符,但是会发生相同的“#1064”错误。

This is made even more confusing because when I use phpmyadmin's interface for creating the same trigger it works fine - but won't when I export the generated SQL and try to create the trigger using that!? 这变得更加令人困惑,因为当我使用phpmyadmin的界面创建相同的触发器时,它可以正常工作-但是当我导出生成的SQL并尝试使用该触发器来创建触发器时,它将无法正常工作!

Thanks for any help 谢谢你的帮助

I didn't realise that, by default, phpmyadmin adds a ; 我没有意识到,默认情况下,phpmyadmin添加了; delimiter which was breaking the ; 分隔符; used to end a statement within the BEGIN END block. 用于结束BEGIN END块内的语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM