简体   繁体   English

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

[英]problem while creating a trigger in mysql error 1064?

I have a problem when creating trigger in mysql : 我在mysql中创建触发器时遇到问题:

Error SQL query: 错误的SQL查询:

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; MySQL说:文档1064-您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 11 检查与您的MySQL服务器版本相对应的手册,以找到在第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 ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM