插入后,删除其他表触发器

时间:2014-07-28 14:22:47

标签: mysql triggers

我想要一个触发器,在user_briefcases

中插入一行后删除user_briefcases_sold中的行

这两个表都有briefcase_iduser_id

我不知道为什么这不起作用:

CREATE TRIGGER delete_user_briefcase_when_sold
DELIMITER $$ 
AFTER INSERT ON user_briefcases_sold FOR EACH ROW BEGIN 
DELETE FROM user_briefcases WHERE briefcase_id = NEW.briefcase_id && user_id = NEW.user_id; 
END; 
$$ DELIMITER ;

1 个答案:

答案 0 :(得分:0)

您有语法错误
试试这个

DELIMITER $$
CREATE 
  TRIGGER delete_user_briefcase_when_sold AFTER INSERT 
  ON user_briefcases_sold 
    FOR EACH ROW BEGIN 
    DELETE FROM user_briefcases WHERE briefcase_id = NEW.briefcase_id AND user_id = NEW.user_id; 
END$$
DELIMITER ;