是的。只是你不能用那个引擎。
编辑。您可以编写一个触发器,一旦您删除表中的一条记录,就会删除所有其他表中的所有子记录。
行。我给你写了一个例子:
create table tab1 (
id int )
engine = myisam;
insert into tab1 values (1),(2),(3),(4);
create table tab2(
id int not null auto_increment primary key,
id_tab1 int
) engine = myisam;
insert into tab2 (id_tab1) values (1),(2),(2),(3),(4);
create table tab3(
id int not null auto_increment primary key,
id_tab1 int
) engine = myisam;
insert into tab3 (id_tab1) values (1),(2),(2),(3),(2);
delimiter //
create trigger deletecascade after delete on tab1
for each row
begin
delete from tab2 where id_tab1 = old.id;
delete from tab3 where id_tab1 = old.id;
end; //
delimiter ;
delete from tab1 where id = 2;
希望它有所帮助。
编辑。显然,即使您同时从 table1 中删除更多 id 它也有效:
delete from tab1 where id in (2,3,4);