🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Avoid deletion of master with details

#11057
From: Stig Andersen
Date: Tue, 17 Dec 2002 22:20
81 lines
3296 bytes
Dear all
A View  - of course!!
I could not get Interbase6 to eat "on delete restrict" and I could not find
that possibility in the Documentation either...

Thank for the input - really useful
Sincerely Stig Andersen


"Bojidar Alexandrov" <bojo@kodar.net> skrev i en meddelelse
news:3dfede65@newsgroups.borland.com...
> Stig Andersen wrote:
> > 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
>
> You raise the error then catch it so nothing happens. If you raise error
out
> of the trigger may  be it will work but
> ugly.
> I recommend you to use a view and make triggers on to take appropriate
> action on the physical table.
>
>
> --
> Bojidar Alexanrov
> Kodar Ltd.
> http://www.Kodar.net
>
>
Technical Details
Message-ID: <3dffa373@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!diablo.theplanet.net!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.icl.net!newsfeed.fjserv.net!lnewspeer01.lnd.ops.eu.uu.net!emea.uu.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3dfe4ecd@newsgroups.borland.com> <3dfede65@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 14:39:22 PST
From: "Stig Andersen" <irene.jorgensen@get2net.dk>
Newsgroups: borland.public.interbase.sql
References: <3dfe4ecd@newsgroups.borland.com> <3dfede65@newsgroups.borland.com>
Subject: Re: Avoid deletion of master with details
Date: Tue, 17 Dec 2002 23:20:33 +0100
Lines: 83
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: 195.47.144.157
Message-ID: <3dffa373@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1040163699 195.47.144.157 (17 Dec 2002 14:21:39 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!diablo.theplanet.net!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.icl.net!newsfeed.fjserv.net!lnewspeer01.lnd.ops.eu.uu.net!emea.uu.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail