Re: Discussing 3 different strategies for deleting from multiple tables
- From: "Stephen Howe" <stephenPOINThoweATtns-globalPOINTcom>
- Date: Mon, 17 Oct 2005 13:39:33 +0100
> Method 1 -
>
> DELETE FROM ACCOUNT WHERE ACCOUNTID = ?
> DELETE FROM CONTACT WHERE ACCOUNTID NOT IN (SELECT ACCOUNTID FROM ACCOUNT)
> DELETE FROM OPPORTUNITY WHERE CONTACTID NOT IN (SELECT CONTACTID FROM
CONTACT)
Seems expensive. If you know the AccountID in the 1st SQL statement, why not
use it the the 2nd, 3rd SQL statements rather than getting the SQL engine to
build an entire list of Account ID's and deleting those not in it? A lot of
work and _NOT_ SQL efficient.
Method 4
-------------
(done in the order not to violate FK constraints - but I read what you said)
DELETE FROM OPPORTUNITY WHERE CONTACTID IN (SELECT CONTACTID FROM CONTACT
WHERE ACCOUNTID = ?)
DELETE FROM CONTACT WHERE ACCOUNTID = ?
DELETE FROM ACCOUNT WHERE ACCOUNTID = ?
Stephen Howe
.
- Follow-Ups:
- References:
- Prev by Date: Re: Discussing 3 different strategies for deleting from multiple tables
- Next by Date: Re: Discussing 3 different strategies for deleting from multiple tables
- Previous by thread: Re: Discussing 3 different strategies for deleting from multiple tables
- Next by thread: Re: Discussing 3 different strategies for deleting from multiple tables
- Index(es):
Relevant Pages
|
|