🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Avoid deletion of master with details

#11060
From: T. van Rompaey
Date: Wed, 18 Dec 2002 09:14
93 lines
3637 bytes
Sorry you are right.

In Interbase it is called 'on delete no action'

Greetings,
Thomas

"Stig Andersen" <irene.jorgensen@get2net.dk> wrote in message
news:3dffa373@newsgroups.borland.com...
> 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: <3e003c5d$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!newsswitch.lcs.mit.edu!news-FFM2.ecrc.net!news-mue1.dfn.de!news-ber1.dfn.de!fu-berlin.de!news.uni-x.net!newsgroups.borland.com!not-for-mail
References: <3dfe4ecd@newsgroups.borland.com> <3dfede65@newsgroups.borland.com> <3dffa373@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-18 01:18:05 PST
From: "T. van Rompaey" <tvrompaey@scabbouw.nlNOSPAM>
Newsgroups: borland.public.interbase.sql
References: <3dfe4ecd@newsgroups.borland.com> <3dfede65@newsgroups.borland.com> <3dffa373@newsgroups.borland.com>
Subject: Re: Avoid deletion of master with details
Date: Wed, 18 Dec 2002 10:14:07 +0100
Lines: 95
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: <3e003c5d$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1040202845 213.84.36.220 (18 Dec 2002 01:14:05 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!newsswitch.lcs.mit.edu!news-FFM2.ecrc.net!news-mue1.dfn.de!news-ber1.dfn.de!fu-berlin.de!news.uni-x.net!newsgroups.borland.com!not-for-mail