I've got a parent table, which has a dozen child tables referencing it. Those child tables in turn have other child tables referencing them. And so on.
I need to delete a row from the main parent table cascading it all the way down.
Dropping/recreating constraints all over the place to have them "ON CASCADE DELETE" is not an option
Going through all of them and deleting child rows manually is a nightmare.
Any other options?
The DELETE statement has no parameters to make it cascading.
So you can either make user of ON CASCADE DELETE
or just execute a bunch of separate deletes in the right order.
You could write a 'smart delete' procedure which investigates table structure and generates a series of deletes bases on that, but that will likely be more work and more of a nightmare than writing the separate deletes. And you'd have to have those constraints for this to work, which in reality is not always desired.