i am having a mysql database, and in one table i have f_id as P_Key and this f_id is referenced in multiple table as f_key. and i want to delete the records of this f_id(let say 10) from all the table in a once. then for this i need to delete in all the table which are having f_id= 10 as f_key then only i can delete this from the main table which contains it as a P_Key. can there be any automated process which can delete this by automatic looking into the table ,I dont want to write down the whole list of the table(as the list is very big more than 18 tables) in the query as this p_key is referenced in many tables.
i am having a mysql database, and in one table i have f_id as
Share
The easiest way to do this is set up an ON DELETE CASCADE CONSTRAINT on your keys such that on deletion of records on your parent table will delete all child records in your other tables that reference that row. Note that you’ll need to delete the foreign keys and and add them again if they don’t have an ON DELETE CASCADE constraint. Something like this: