sql – Delete from multiple tables with the same key

Question:

There are tables: a, b, c, d.
All tables have the same FK = IDXXX .

Is it possible to delete records from all tables using this key with one query?

Something like this:

DELETE FROM a,b,c,d WHERE IDXXX = 'YYYY';

Answer:

Impossible.

If you need delete integrity, wrap a delete from all tables in a single transaction, rolling back the entire transaction in the event of a problem with a delete from any table.

Scroll to Top