Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MYSQL trigger syntax - missing semicolon

Tags:

mysql

triggers

I'm relatively new to MYSQL from an MS SQL background. Can someone please point out why I'm getting syntax errors here please? I'm sure I've done something very obviously wrong but I just can't see it:

I'm getting a missing semicolon syntax error on line 8:

CREATE TRIGGER trg_InsertProductWatchListPriceHistory
AFTER UPDATE
ON ProductWatchlist FOR EACH ROW
BEGIN
INSERT INTO ProductWatchListPriceHistory 
(ProductWatchlistID,Price) 
VALUES  
(ProductWatchlistID,New.ProductPrice);
END;

Any help greatly appreciated.

like image 524
Giles Hunt Avatar asked Dec 08 '22 21:12

Giles Hunt


1 Answers

You need to change your default delimiter to something else than ;. Otherwise your definition ends at the first ; which would make it incomplete.

delimiter |
CREATE TRIGGER trg_InsertProductWatchListPriceHistory
AFTER UPDATE
ON ProductWatchlist FOR EACH ROW
BEGIN
   INSERT INTO ProductWatchListPriceHistory (ProductWatchlistID, Price) 
   VALUES (New.ProductWatchlistID, New.ProductPrice);
END
|
delimiter ;
like image 192
juergen d Avatar answered Dec 18 '22 08:12

juergen d