Reputation: 123
I have a problem when creating trigger in mysql :
Error SQL query:
CREATE TRIGGER product_after_insert
AFTER INSERT
ON FRUITS FOR EACH ROW
BEGIN
INSERT INTO products
( category,
product_id)
VALUES
( 'fruit',
New.ID)
MySQL said: Documentation 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 11
Upvotes: 1
Views: 68
Reputation: 28864
Please find the fixed Trigger with inline comments about errors:
-- need to define DELIMITER to something else other than ;
DELIMITER $$
CREATE TRIGGER product_after_insert
AFTER INSERT
ON FRUITS FOR EACH ROW
BEGIN
INSERT INTO products
(category,
product_id)
VALUES
('fruit',
New.ID); -- ; was missing for statement execution
END $$ -- End the Begin clause
DELIMITER ; -- Redefine the delimiter back to ;
Upvotes: 2