When you manipulate data from a database, it is assumed that you know the database, or you would not know what you are doing.
Disabling the constraints temporarily solves? I don’t think so because then you’ll have to call back then anyway you might not have corrupted the record linkage.
That is, you don’t escape knowing what you’re doing, you need to know relationships beforehand and you need to know the implications of deleting a record with dependencies.
The option that makes the most sense to me is delete the records in the order of their dependencies, first the children and then the parents, instead of pretending to ignore these dependencies.
You can still do the mass deletion: delete the 1500 children records, then the 1500 parent records and then their parents and so on.
If deleting dependencies when deleting a parent is a standard procedure for these tables, then I get the Math option: change the table so as to automatically and permanently delete dependencies.
Now, if you really don’t care about the data
If you are for example using a test base may be applicable from time to time to quit deleting records and destroying dependencies as if there were no tomorrow.
In this case an option is a script that retrieves the table metadata and traverses the dependencies by doing the deletion in the correct order.
This script can be a client-side break code in the language of your choice, or a stored Procedure.
but I have to do it for all the tables?
– PatiiHenrii
@Patiihenrii Do you want the command for all tables as well? Do not recommend it. The ideal is to use only for the tables involved with your change.
– Leonel Sanches da Silva
got it, I’ll test it here, on the test bench I got! Thanks.
– PatiiHenrii