且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 mysql 错误 1064 中创建触发器时出现问题?

更新时间:2023-10-09 09:21:22

请找到带有关于错误的内联注释的固定触发器:

-- 需要将 DELIMITER 定义为除 ; 以外的其他内容.分隔符 $$创建触发器 product_after_insert插入后每行水果开始插入产品(类别,产品编号)价值观('水果',新.ID);-- ;缺少语句执行END $$ -- 结束 Begin 子句分隔符;-- 将分隔符重新定义为 ;

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 ;