5

我有 2 个表 A(id, Name), B(id, fid, Name) 其中A.id = B.fid,我的要求是每当 A 中的行删除时我想删除 B 中的行

这是我尝试过的查询,但它在 B 附近给了我错误。

Create Trigger Delete_B_trigger After Delete on A For each row Begin Delete from B where fid = id; End
4

1 回答 1

16

DELETE 命令需要一个 FROM。

要访问触发表中的值,您必须使用OLD 或 NEW别名。

CREATE TRIGGER Delete_B_trigger
AFTER DELETE ON A
FOR EACH ROW
BEGIN
    DELETE FROM B WHERE fid = OLD.id;
END
于 2013-03-04T08:59:52.053 回答