Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: constraint or trigger ?
Hi Serge,
Rgds
Andrew
Serge LUCAS wrote:
> I want to attach the following kind of constraint to a table which
> contains 2 external foreign keys 'ext1ID' & 'ext2ID':
> "There can be at most TWO lines referencing these two keys"
>
> - At first, I wanted to create a BeforeInsert trigger, but I dont' know
> how to make cancel the INSERT if the condition is not checked: will an
> exception be enough, or even if an exception occurs in a trigger, is the
> corresponding request however performed ?
>
> - The other solution would be to create a function which calculates
> (select count(*)) the number of lines that already have these two keys,
> and attach a constraint to MyTable which uses this function:
> Alter table MyTable add constraint MyConstraint check (f(x,y)<2);
>
> I have the Oracle error ORA-00904, which let me think I cant call a
> function in a constraint...
>
> I would like to avoid the third solution which consists in adding the
> following column to MyTable:
> checking NUMBER, UNIQUE, NOT NULL, IN (1,2);
>
> Could somebody help me ?
>
> --
> Serge LUCAS
> STERIA ATM/Eurocontrol
> BS-012
> Tel 01 69 88 74 15
> Fax 01 69 88 73 33
> Mel lua_at_eurocontrol.fr
Received on Tue Mar 30 1999 - 02:48:51 CST
![]() |
![]() |