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
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 ;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.