Cascade Delete request

I have three tables. Product, company, employee

ProductId from the product table is the key for the company and "CompanyId of Company" is the key for the Employee.

Thus, when deleting ProductId from the Product table, all related records in other tables must be deleted. But I cannot touch the circuit (I cannot use the alter table). How should I write a request in this case.

+4
source share
2 answers

If you cannot add restrictions that propagate the deletion, you must write all the necessary deletions yourself:

delete employee where companyid in (select companyid from company c where productid = xxx); delete company where productid=xxx; delete product where productid=xxx; 
+7
source

Try this option. I have no environment to verify this. I think with some changes it should work in the end.

 DELETE Product,Company,Employee FROM user LEFT JOIN items ON product.productid = company.productid LEFT JOIN orders ON company.productid = product.productid WHERE product.productid = [$productid] 
0
source

All Articles