简体   繁体   English

MySQL触发器不起作用,语法错误

[英]MySql trigger not working, syntax error

I have tried to create the following trigger but it is not working: 我尝试创建以下触发器,但是不起作用:

delimiter //
CREATE TRIGGER DeleteFeature
AFTER DELETE ON Features
FOR EACH ROW BEGIN        
    IF (OLD.FeatureID IN (SELECT FeatureID FROM GroupFeatures)) THEN
      INSERT INTO DeletedFeatures VALUES (OLD.FeatureID, OLD.FeatureName, OLD.FeatureDescription);
    END IF;
END; 
//

It is giving the following error: 它给出了以下错误:

"#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 8 " “#1064-您的SQL语法有误;请查看与您的MySQL服务器版本相对应的手册,以找到在第8行'//'附近使用的正确语法”

Any ideas what the problem could be? 任何想法可能是什么问题?

Have you checked by removing the semi-colon and add $$ after the END 您是否已通过删除分号并在END之后添加$$进行了检查

DELIMITER $$
CREATE TRIGGER DeleteFeature
AFTER DELETE ON Features
FOR EACH ROW 
  BEGIN        
    IF (OLD.FeatureID IN (SELECT FeatureID FROM GroupFeatures)) THEN
      INSERT INTO DeletedFeatures VALUES (OLD.FeatureID, OLD.FeatureName OLD.FeatureDescription);
    END IF;
  END $$
DELIMITER ;

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

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