MySql触发器无法正常工作,语法错误

时间:2015-04-16 22:14:19

标签: php mysql sql database triggers

我试图创建以下触发器,但它不起作用:

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; 
//

出现以下错误:

"#1064 - 您的SQL语法出错;检查与您的MySQL服务器版本对应的手册,以便在' //'附近使用正确的语法。在第8行"

任何想法可能是什么问题?

1 个答案:

答案 0 :(得分:0)

您是否通过删除分号进行检查,并在$$

之后添加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 ;