1

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

1

1 Answer 1

2

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 ;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.