I'm creating a contact management system that records a company's contact details, contact person, campaign, submitted proposals by the company, and donation.
One company can have many contact people, can submit many proposals in many campaigns, and can donate for many campaigns. It's not required for a company to have contact person, to submit any proposal and to give any donation. I have successfully made queries using INSERT, UPDATE, and SELECT but not DELETE. Right now I'm using this query to delete a company and all of its related data:
DELETE organizations.*, contactdetails.*, proposalorg.*, donationorg.*
FROM organizations, contactdetails, proposalorg, donationorg
WHERE idOrg='$id' AND
contactdetails.company_id=organizations.idOrg AND
proposalorg.company_id=organizations.idOrg AND
donationorg.company_id=organizations.idOrg
I know it will not delete the company if there are any errors with this query. I have read about DELETE CASCADE as a better option, but I'm not sure how to do it. If anyone has any idea on how to do it, I would really appreciate it.