如果我有一个父表和子表,是有可能多删除其行,而不必一个“ON DELETE CASCADE”的约束?
在这个例子:
create table a(id int primary key);
create table b(id int primary key, a_id int,
constraint fkb foreign key (a_id) references a(id));
它是不可能做这样的事情,以删除表A和B行? :-(
delete a, b
from b
inner join a on a.id = b.a_id
where a.id = ?;
Error Code: 1451. Cannot delete or update a parent row: a foreign key constraint fails
(`erasmusu6`.`b`, CONSTRAINT `fkb` FOREIGN KEY (`a_id`) REFERENCES `a` (`id`))
我想multidelete行,但不设定“ON DELETE
CASCADE”的约束 。 此外,我需要过滤DELETE
的命令WHERE
子句。 这是可能的,或者我应该有使尽可能多的DELETE
S作为在multidelete表?