Sergey Onishchenko
Sergey Onishchenko

Reputation: 7851

MySql Triggers Error

I have 2 tables in MySql dealers and dealers_info. I try to create trigger which after deleting info from dealers will delete corresponding rows from dealers info

CREATE TRIGGER del_info AFTER DELETE ON  dealers
FOR EACH ROW 
BEGIN
DELETE FROM dealers_info WHERE dealer_id = OLD.dealer_id;
END;

But I've got an error:

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

Upvotes: 0

Views: 79

Answers (1)

John Woo
John Woo

Reputation: 263683

change the delimiter to execute the query properly,

DELIMITER $$
CREATE TRIGGER del_info 
AFTER DELETE ON  dealers
FOR EACH ROW 
BEGIN
    DELETE FROM dealers_info WHERE dealer_id = OLD.dealer_id;
END $$
DELIMITER ;

Upvotes: 1

Related Questions