Re: [Newbie] Cascade delete manually
| From: | Bobby Rahman | Date: | Thu, 01 May 2003 11:02:42 +0000 |
| Subject: | Re: [Newbie] Cascade delete manually | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-145925@lists.php.net to get a copy of this message | ||
So if mysql doesnt support cascade and nested queries can someone tell me how they get around deleting from more than one table. I suppose im really stuck on looping through one table and deleting all the rows.
Here I go again:
I can see the projid of the project wishes to delete and also I can see
all the bugs which exist in that project by doing:
select * from bug where bug.projid='$projid'
But how do I do the logic for every bug that is within that project check to see if it has bug followups and if so delete them per bug untill all bug followups have been deleted then delete the bug then finally delete the project.
DO I need to use some sort of loop to delete?
Going into my example in first email:
would I use:
Delete * from bug_follow_up where bug_follow_up.bugid=bug.bugid.
Delete * from bug where bug.bugid=project_followup.bugid
Delete * from project where projid='$projid'
Cheers
Bobby
From: "Bobby Rahman" <bobby_rahman2002@hotmail.com> To: php-general@lists.php.net Subject: [PHP] [Newbie] Cascade delete manually Date: Thu, 01 May 2003 05:22:38 +0000 Hiya I just wanted to know if there was any tips people could offer me regarding cascade deletes. im using mysql and want to hard code delete query that traverses the necesssary tables using php. For e.g. I had a Project table, which contains loads of bugs (in the bug table). Every bug is stored with the foreign key projid so to know which bugs are related to which projects. Now inside every bug I allow the option to add a followup to update the bug such as status of the bug....(This data stored in the bug_followup table). Now say I want to delete a project I can get all the bugs in that project with: select bugid from bug, project where bug.projid=project.projid; Now I can get all the followups of the bug also doing(im guessing): select * from bug_followup, bug where bugid=bug.bugid. But just not sure how to join up the queries?I should do this? Is there a way to build a nested query such as in php: delete * from bug_followup where bugid =(select bugid from bug where projid=$projid; Thanx Bobster _________________________________________________________________ Hotmail messages direct to your mobile phone http://www.msn.co.uk/mobile -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php_________________________________________________________________ Get Hotmail on your mobile phone http://www.msn.co.uk/mobile