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

Madhur Bhaiya
  • 28,155
  • 10
  • 49
  • 57
Mohammed Chanaa
  • 93
  • 2
  • 10
  • Possible duplicate of [How can I fix MySQL error #1064?](https://stackoverflow.com/questions/23515347/how-can-i-fix-mysql-error-1064) – Nick Nov 17 '18 at 12:02

1 Answers1

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 ;
Madhur Bhaiya
  • 28,155
  • 10
  • 49
  • 57