MySQL Multi-Delete. Can I delete referenced lines multiple times?

If I have a parent table and a child table, is it possible to repeatedly delete rows in them without the “DELETE CASCADE” restriction?

In this example:

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));

Is it possible to do something similar to delete rows in tables a and 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`))

I need multi-line strings, but don't set the ON DELETECASCADE limit . I also need to filter the command DELETEwith the sentence WHERE. Is this possible, or do I need to do as much DELETEas tables in multi-user?

+1
source share
2 answers

, DELETE:

delete a, b
from b
STRAIGHT_JOIN a on a.id = b.a_id
where a.id = ?;

MySQL b STRAIGHT_JOIN.

+1

mysql (http://dev.mysql.com/doc/refman/5.0/en/delete.html):

" DELETE , InnoDB, , MySQL , / ., . ON DELETE, InnoDB .

, , !

, .

0

Source: https://habr.com/ru/post/1627109/


All Articles