PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 24, 2022

[FIXED] MySQL 5.7 Create Trigger Syntax Error?

 January 24, 2022     mysql, mysql-5.7, phpmyadmin, sql, triggers     No comments   

Issue

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.

Here's the 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

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.

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!?

Thanks for any help


Solution

I didn't realise that, by default, phpmyadmin adds a ; delimiter which was breaking the ; used to end a statement within the BEGIN END block.



Answered By - Scott Barbour
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing