Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Question about Constraint

RE: Question about Constraint

From: Stephane Faroult <sfaroult_at_oriolecorp.com>
Date: Fri, 29 Aug 2003 02:24:33 -0800
Message-ID: <F001.005CDF27.20030829022433@fatcity.com>


>Hallo,
>
>I would like to gets ome help on this:
>
>I have this table
>
>Id Companynumber First Name LastName
>Type
>
>1 123 Jim Andersson 1
>2 234 Tom Perkins
> 2
>3 565 Henry Ford 1
>
>
>I would like to have a constraint so when I try to
>add and the same companynumber that already
>exists(for instance 234)
>I am not allowed to do this if the filed Type has
>the value 1.
>So if I add a companynumber which already exists
>and the Type is 2, then I should be allowed to add
>this companynumber.
>
>Maybe this is simple but woul dreally appreciate
>some help onhow to write this.
>
>Roland
>

You can't do that through declarative constraints and you'll have to resort to a trigger to implement it - a pre-insert row trigger which does a 'select type ... where CompanyNumber = :new.companynumber and rownum=1'. Quite obviously (????) for performance reasons you should have an index (albeit a non-unique one) on (companynumber, type). If you have found a type and it's one, raise an exception. You have quite a number of hidden traps though :

Regards,

Stephane Faroult
Oriole

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: Stephane Faroult
  INET: sfaroult_at_oriolecorp.com

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Fri Aug 29 2003 - 05:24:33 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US