I have a problem that I did not find anything on Google (maybe I did not know how to ask him)
Imagine the following:
-
I have 11 tables, one call tbl_pai and 10 other calls tbl_filha1 , tbl_filha2 , tbl_fila / em>.
- / li>
That is, 10 tables that have foreign keys referenced to the main table
The question is: How can I elegantly test whether or not I can remove a tuple from the main table? I could only think of two options: Try to delete the parent record and treat the error if the record is referenced in another table, or do a COUNT in all the child tables to see if there is a dependency .
I need this information to decide whether or not to make a DELETE button available in my application. If the record does not have reference, I display the button, otherwise I hide the button. The problem is that this button is in a listing (of 'parent' records) and this check needs to be done for each record. I did it using COUNT but it was extremely slow since the 'parent' table has more than a million records.
Is there a less costly method?
Thank you guys.