Subject | Re: Trigger to prevent a deletion? |
---|---|
Author | sgharp |
Post date | 2004-08-02T16:10:41Z |
--- In firebird-support@yahoogroups.com, "Martijn Tonies"
<m.tonies@u...> wrote:
just disallow the deletion. I don't want my client application to
have to handle the exception; I just want the record to not be
deleted. Is there another way?
Steve
<m.tonies@u...> wrote:
> Hi,be
> >
> > I have some tables that contain records that the user should not
> > able to modify or delete. Other records in the same tableshould be
> > freely modified, deleted, whatever. I'm trying to come up witha
> > an 'on update or delete' trigger that will prevent the change if
> > field value exists.there a
> >
> > if (NEW.SomeField = 0) then
> > DoNotChangeMe;
> >
> > Is something like this possible from within a trigger or is
> > better way to protect these records at the server level?delete
>
> You can do this via a trigger that raises an exception...
>
> Here's an example:
> CREATE EXCEPTION DELETE_NOT_ALLOWED 'System data - not allowed to
> this.';DELETE POSITION
>
>
> SET TERM ^^ ;
> CREATE TRIGGER CATEGORIE_SYSTEEM FOR CATEGORIE ACTIVE BEFORE
> 0 ASI can see where this would work but I would prefer that the server
> BEGIN
> if (old.SYSTEEM = 'T')
> then exception DELETE_NOT_ALLOWED;
> END
> ^^
> SET TERM ; ^^
>
> Of course, you DO need to handle the exception :-)
just disallow the deletion. I don't want my client application to
have to handle the exception; I just want the record to not be
deleted. Is there another way?
Steve