Subject Re: [ib-support] Delete from two tables at once
Author Lucas Franzen
Robert Munro schrieb:
>
> I have to tables (A and B), and I want to delete records from both of
> them that exist in both of them. If a record exists in only one, then
> I don't want to delete it.
>
> This would be the easiest way to do it:
>
> delete from A where id in (select id from B)
>
> The problem is that after I delete them table A, I loose my record of
> what to delete from B, so I can't follow up with:
>
> delete from B where id in (select id from A)
>
> as the records have already gone.
>
> Any suggestions?

If they aren't linked by foreign key constraints (with cascading
deletes) as Martijn asked you the best should be to write a stored
procedure that takes all records from either table and if there's also a
(or more) record(s) in the other one you can do two deletes.

Luc.