I have a database full of customer data. It’s so big that it’s really cumbersome to operate on, and I’d rather just slim it down to 10% of the customers, which is plenty for development. I have an awful lot of tables and I don’t want to alter them all with ‘ON DELETE CASCADE’, especially because this is a one-time deal.
Can I do a delete operation that cascades through all my tables without setting them up first? If not, what is my best option?
Combining your advice and a script I found online, I made a procedure that will produce SQL you can run to perform a cascaded delete regardless of
ON DELETE CASCADE. It was probably a big waste of time, but I had a good time writing it. An advantage of doing it this way is, you can put aGOstatement between each line, and it doesn’t have to be one big transaction. The original was a recursive procedure; this one unrolls the recursion into a stack table.