Subject | Re: [firebird-support] On Delete triggers and referential integrity |
---|---|
Author | Martijn Tonies |
Post date | 2003-06-17T10:30:55Z |
Hi Tom,
ALTER TABLE ADRES ADD CONSTRAINT FK_ADRES_LAND
FOREIGN KEY (LANDCODE) REFERENCES LAND
(LANDCODE)
ON DELETE NO ACTION
ON UPDATE CASCADE
As you can see, DELETEs aren't possible - now this:
delete from land <run>
Raises an exception with this text:
violation of FOREIGN KEY constraint "FK_ADRES_LAND" on table "ADRES"
So I guess you should tell the user what's going on :-)
With regards,
Martijn Tonies
Database Workbench - the developer tool for InterBase & Firebird
Upscene Productions
http://www.upscene.com
> >Well, you CAN write a BEFORE DELETE trigger - but on theanything
> >other hand, a FK will allow you to raise an error if there's a
> >detail record as well. This, btw, is the default.
>
> Thanks, this is exactly what I am looking for - do I have to write
> into the metadata, or will it raise its own exception?It will raise its own exception. An example, this constraint:
ALTER TABLE ADRES ADD CONSTRAINT FK_ADRES_LAND
FOREIGN KEY (LANDCODE) REFERENCES LAND
(LANDCODE)
ON DELETE NO ACTION
ON UPDATE CASCADE
As you can see, DELETEs aren't possible - now this:
delete from land <run>
Raises an exception with this text:
violation of FOREIGN KEY constraint "FK_ADRES_LAND" on table "ADRES"
So I guess you should tell the user what's going on :-)
With regards,
Martijn Tonies
Database Workbench - the developer tool for InterBase & Firebird
Upscene Productions
http://www.upscene.com