Question

I'm running into a problem with creating a trigger on a table using MySQL and phpmyadmin v3.4.5. After some research, it seems like this is a common problem, but none of the fixes I've found are working for me. The error I'm getting is:

 #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 'END' at line 8

The query I'm trying to run is:

 CREATE TRIGGER book_insert
 AFTER INSERT ON `books`
 FOR EACH ROW BEGIN
 INSERT INTO products
      (ProductID,Type,Title,Price) 
 VALUES 
      (books.ProductID,0,books.Title,0)
 END
 //

I've set the delimiter to // in the text below the query input as I've read that PHPMyAdmin doesn't like you using the delimiter keyword in the query. I've also played around with the placement of the delimiter, having no spaces between END and '//', having one space, and trying it on a different line. I've also tried different delimiters like the default semicolon, 2 dollar signs, and 2 pound signs. This seems like its something really small and stupid, but I can't figure out what it doesn't like about that statement.

Was it helpful?

Solution 2

So I finally got it to work by removing BEGIN and END from the query and not using any delimiters at all. I'm not sure if my version of MySQL has some issue with the BEGIN/End statement or something, but the trigger was finally created.

OTHER TIPS

DELIMITER is not SQL syntax, it's a command that the mysql command line client accepts to change how it reads and sends queries to the server. Neither PhpMyAdmin nor the server know anything about it.

Simply send the trigger as a query without the trailing // in this case. Or to get PMA to execute it properly you may have to put it in a file and send it. I'm not sure exactly because I've found that PMA as a tool often does silly things like this which make your life more difficult.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top