> [snip]
> I am using MySQL with a PHP front end.  Is there a better way to delete
> from multiple tables than the following?
>       $result=mysql_query("DELETE FROM team WHERE team_id = '$team_id'");
>       $result=mysql_query("DELETE FROM conflicts WHERE team_id =
> '$team_id'");
>       $result=mysql_query("DELETE FROM home_field WHERE team_id =
> '$team_id'");
> [/snip]
>
> This is where MySQL currently fails on of the 12 rules of an RDBMS..it has
> not the ability to CASCADE and true table relatons are lacking. I have
> always handled it in the code, like you have done above, until
> MySQL becomes
> more robust in it's query features...

If you're using MySQL 4.0.x, you can do:

DELETE team, conflicts, home_field FROM team, conflicts, home_field WHERE
team.team_id = conflicts.team_id AND team.team_id = home_field.team_id AND
team.team_id = '$team_id'

In 3.23.50+ and 4.0.2+ InnoDB supports ON DELETE CASCADE, and ON DELETE SET
NULL, so you wouldn't even need the multi-table delete.

-JF


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to