Stefanos Chrs
Stefanos Chrs

Reputation: 2518

MySQL AFTER UPDATE TRIGGER to increase count

Any ideas what's wrong with this query? I searched around stackoverflow and it seems everyone is using this and it works.

mysql> CREATE TRIGGER upd_entry 
    -> AFTER UPDATE ON entry FOR EACH ROW
    -> BEGIN
    ->     UPDATE entry 
    ->     SET count = count +1 
    ->     WHERE id = NEW.id
    -> END;
ERROR 1064 (42000): 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 7

Upvotes: 0

Views: 1513

Answers (2)

Mihai
Mihai

Reputation: 26784

Run this first to change the delimiter

DELIMITER //

create the trigger

CREATE TRIGGER upd_entry 
AFTER UPDATE ON entry FOR EACH ROW
BEGIN
   UPDATE entry 
   SET count = count +1 
   WHERE id = NEW.id;
END//

After change it back

DELIMITER ;

Upvotes: 1

Abdulla Nilam
Abdulla Nilam

Reputation: 38584

forget ; at end of line

CREATE TRIGGER upd_entry 
AFTER UPDATE ON entry FOR EACH ROW
BEGIN
   UPDATE entry SET count = count +1 WHERE id = NEW.id;//forget to close line ;
END;//
delimiter;

Mysql Trigger

Upvotes: 0

Related Questions