假设我有一个父表:FAMILY_MEMBER
,每个都有unique ID
个ID。
我还有FAMILY
表mother_id
,father_id
和daughter_id
,每个表都指向FAMILY_MEMBER
行。
当我删除FAMILY
行时,我希望数据库自动删除3 FAMILY_MEMBER
个父行。这似乎与ON DELETE
和ON UPDATE
条款的目的完全相反。
答案 0 :(得分:0)
create trigger t1
after delete on FAMILY
for each row
BEGIN
delete from family_member
where id = old.mother_id;
delete from family_member
where id = old.fa=ther_id;
delete from family_member
where id = old.daughter_id;
END
或者这个(您可以使用分隔符作为触发器和表的名称):
create trigger `t1`
after delete on `FAMILY`
for each row
BEGIN
delete from family_member
where id = old.mother_id;
delete from family_member
where id = old.fa=ther_id;
delete from family_member
where id = old.daughter_id;
END