Delete across 5 Joined tables
Delete across 5 Joined tables
От:
Fuzzygoth <dav.phillips@ntlworld.com>
Дата:
Hi, I am trying to delete a set of related record across the whole database, In tests I have managed to delete records from 2 tables using the code below. DELETE FROM phillipsd.tablea using phillipsd.tableb WHERE tablea.one = 2; but I need to be able to delete from up to 5 different tables, is there a quick and simple way of doing this? can someone post an example? Cheers David P
Re: Delete across 5 Joined tables
От:
Raymond O'Donnell <rod@iol.ie>
Дата:
On 15/08/2008 11:08, Fuzzygoth wrote: > but I need to be able to delete from up to 5 different tables, is > there a quick and > simple way of doing this? can someone post an example? Just guessing without more detailed information, but are the tables related one-to-many using foreign keys? If so, when defining the foreign key you can set the delete to cascade whenever a "master" row is deleted: alter table foo add constraint foo_fk foreign key [...] on delete cascade; ...or something like that. Ray. ------------------------------------------------------------------ Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland rod@iol.ie Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals ------------------------------------------------------------------