我尝试为每个新帖子创建触发器
这是我的代码
CREATE TRIGGER insertprod AFTER INSERT ON post
FOR EACH ROW
BEGIN
INSERT INTO attributes SET attrtext = 'sometext', post_id = NEW.id;
END;
我收到这个错误
最佳答案
您可能只需要一个定界符:
DELIMITER $$
CREATE TRIGGER insertprod AFTER INSERT ON post
FOR EACH ROW
BEGIN
INSERT INTO attributes SET attrtext = 'sometext', post_id = NEW.id;
END;
$$
DELIMITER ;
但是,您还使用
INSERT
的非标准形式。我会建议:DELIMITER $$
CREATE TRIGGER insertprod AFTER INSERT ON post
FOR EACH ROW
BEGIN
INSERT INTO attributes(attrtext, post_id)
VALUES('sometext', NEW.id);
END;
$$
DELIMITER ;
关于mysql - MySQL创建触发器引发错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32297149/