🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Avoid deletion of master with details

#11039
From: T. van Rompaey
Date: Tue, 17 Dec 2002 09:49
67 lines
2927 bytes
Set the foreign key to 'delete restrict' instead of on 'delete update'. This
should prevent the row from being deleted.
I'm not sure what the best way is to set the Obsolete, but I would recomment
your 'middle tier' (if you have one)

Greetings,
Thomas

The problem you have is that a trigger cannot stopt the started action
(Delete in this case)
"Stig Andersen" <irene.jorgensen@get2net.dk> wrote in message
news:3dfe4ecd@newsgroups.borland.com...
> Hi,
>
> How do I avoid that a master record is deleted if it has details (on the
> server side):
> BUT instead of being deleted it should instead be "marked obsolete"
> For example
>
> create MASTER_TABLE
> (
>  MASTER_ID integer not null primary key,
> OBSOLETE smallint /*, ("Boolean")
>  M_Field2 something*/
> );
> create DETAIL_TABLE
> (
> DETAIL_ID integer not null primary key,
> MASTER_ID integer/*,
> D_Field1 something*/
> );
> alter table DETAIL_TABLE add foreign key (MASTER_ID)
>  references MASTER_TABLE(MASTER_ID) on cascade update on delete update;
>
> My solution (which is NOT ideal):
> create Exception CANNOT_DELETE 'Sorry, no delete';
> set term ^;
> create trigger MASTER_TABLE_BD for MASTER_TABLE
> active before delete
> as
>  declare variable CNT integer;
>  begin
>   SELECT COUNT(*)
>    from DETAIL_TABLE
>    where DETAIL_ID = OLD.DETAIL_ID
>    into :CNT;
>   if (:CNT > 0) then
>     exception CANNOT_DELETE;
> /* the following does not work like I had imagined:
>  WHEN ANY do
>    begin
>     update MASTER_TABLE
>     set OBSOLETE = 1
>     where MASTER_ID = OLD.MASTER_ID;
>   end */        /*see what I try to do? - but the row gets deleted
> anyway!!*/
>  end^
> set term ;^
>
> I know it can be done in a TIBDataSet, but that is on the client, not the
> Database.
> Any suggestions are much appreciated.
>
> Sincerely
>  Stig Andersen
>
>
Technical Details
Message-ID: <3dfef33a@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!sn-xit-08!supernews.com!newsfeed.news2me.com!canoe.uoregon.edu!logbridge.uoregon.edu!uunet!sea.uu.net!sac.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3dfe4ecd@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 114a0e,f0f7fed5515a9c91
X-Google-Attributes: gid114a0e,public
X-Google-ArrivalTime: 2002-12-17 01:51:05 PST
From: "T. van Rompaey" <tvrompaey@scabbouw.nlNOSPAM>
Newsgroups: borland.public.interbase.sql
References: <3dfe4ecd@newsgroups.borland.com>
Subject: Re: Avoid deletion of master with details
Date: Tue, 17 Dec 2002 10:49:47 +0100
Lines: 69
Organization: SCAB
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 213.84.36.220
Message-ID: <3dfef33a@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1040118586 213.84.36.220 (17 Dec 2002 01:49:46 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!sn-xit-08!supernews.com!newsfeed.news2me.com!canoe.uoregon.edu!logbridge.uoregon.edu!uunet!sea.uu.net!sac.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail