🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.interbase.sql
Article #830

Re: DELETEing orphaned records

#830
From: Dan Palley
Date: Tue, 15 May 2007 16:46
41 lines
2200 bytes
Paul, take a look at foreign key constraints.  If the constraints are 
defined properly (ON DELETE CASCADE), then the child records are deleted 
automatically when the parent record is deleted.

Dan

"esnpe" <esnpe@hotmail.co.uk> wrote in message 
news:Xns9931714AB38D3esnpehotmailcouk@207.105.83.66...
> Mainy thanks Danny. I'm new to interbase/firebird (actually using the
> latter) and know only basic SQL at the moment. Now I know why I couldn't
> find the correct syntax.
>
> The task records should've been deleted when the server records were
> deleted. This is a one-off and I saw examples of delete using a join in
> other SQL databases.
>
> cheers
> Paul
>
> Van den Wouwer Danny <danny.van.den.wouwer@pandora.be> wrote in
> news:4646d064$1@newsgroups.borland.com:
>
>> Hi Paul,
>>
>> You can't use joins in a delete:
>>
>> I have 2 solutions in mind:
>>
>> 1) DELETE
>>       FROM "Tasks" T
>>      WHERE NOT EXISTS (
>>              SELECT *
>>                FROM "Servers" S
>>               WHERE S."ClientName" = T."ClientName"
>>                 AND S."ServerName" = T."ServerName")
>>
>> --> This isn't the fasted way to go, because the table "Tasks" will be
>> scanned naturally.
>>
>> 2) Write a small stored procedure
>> 
Technical Details
Message-ID: <4649e455$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <4646cba7@newsgroups.borland.com> <4646d064$1@newsgroups.borland.com> <Xns9931714AB38D3esnpehotmailcouk@207.105.83.66>

Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,917a31690354dae3
X-Google-Attributes: gid114a0e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Dan Palley" <dan@trams.com>
Newsgroups: borland.public.interbase.sql
References: <4646cba7@newsgroups.borland.com> <4646d064$1@newsgroups.borland.com> <Xns9931714AB38D3esnpehotmailcouk@207.105.83.66>
Subject: Re: DELETEing orphaned records
Date: Tue, 15 May 2007 09:46:28 -0700
Lines: 43
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3028
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 208.176.170.130
Message-ID: <4649e455$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1179247701 208.176.170.130 (15 May 2007 09:48:21 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail