View Single Post

   
  #3 (permalink)  
Old 02-28-2008, 07:55 AM
frizzle
 
Posts: n/a
Default Re: Delete against multiple tables + And / Or


Axel Schwenke wrote:
> "frizzle" <phpfrizzle@gmail.com> wrote:
>
> > songs -> id, artist_id, song_name
> > lyrics -> id, song_id, lyrics
> > genre -> id, song_id, genre_name
> >
> > Now to delete the song (1 record), *possbile* lyrics (maybe 1 record,
> > maybe none), and *possible* genre-links (max unlimited records),
> > i use the following query:
> >
> > DELETE s.*, l.*, c.*
> > FROM `songs` s,
> > `lyrics` l,
> > `genres` g
> > WHERE s.`id` = $id
> > AND l.`song_id` = $id
> > AND g.`song_id` = $id

>
> Why not using 3 DELETE statements? Alternatively (much better) you may
> go for real foreign key constraints and the ON DELETE CASCADE option.
>
> http://dev.mysql.com/doc/refman/5.0/...nstraints.html
>
>
> XL
> --
> Axel Schwenke, Senior Software Developer, MySQL AB
>
> Online User Manual: http://dev.mysql.com/doc/refman/5.0/en/
> MySQL User Forums: http://forums.mysql.com/


I assumed a single query would be faster.
I will look in your options later on. Thanks a lot.

Frizzle.

Reply With Quote