I have a parent table with collection of IDs, how to transferred this collection to other tables in a block WHERE for deletion?
example:
select id from table_a <- it's collection of ids.
delete from table_b where table_b.ad_id in (COLLECTION_OF_IDS_FROM_PREVIOS_SQL_SCRIPT)
delete from table_c where table_c.ad_id in (COLLECTION_OF_IDS_FROM_PREVIOS_SQL_SCRIPT)
...
there is no possibility to cascade deletion
I find solution
delete from table_b where table_b.ad_id in (select id from table_a)
...
how to optimize this solution?
BEGIN TRANSACTION, then issue the series of SQL commands necessary to accomplish the transfer, thenCOMMIT. (If something goes wrong,ROLLBACK.) When you do this, then, from the point-of-view of any other user, "either everything happened at once, or nothing did." (They will not see "intermediate states.") Usetry..exceptlogic in your programming to ensure that aROLLBACKhappens if a bug occurs.