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

Home -> Community -> Usenet -> c.d.o.misc -> Two-column Referential Integrity Constraint where one one colum value is a constant

Two-column Referential Integrity Constraint where one one colum value is a constant

From: Lonnie Blevins <lblevins_at_regenstrief.org>
Date: Thu, 23 Aug 2001 08:01:51 -0500
Message-ID: <9m2to7$9mq$1@hercules.iupui.edu>


Using some sample names here, we have a "Code" table that contains of a "CodeSystem" column and a "CodeValue" column, for which there is a unique (primary key) index. In table TestTable, we have a column TestColumn which should contain a value defined in one the CodeValue columns for a Code row with a fixed/constant CodeSystem value. That is, the column TestColumn should always contain a value from the 'FixedSystemName' CodeSystem. We have been unable to figure out how to define a referential integrity constraint to enforce this relationship.

Two of our previous attempts/quesses looked like:

ALTER TABLE TestTable
CONSTRAINT TestConstraint
Foreign Key ('FixedSystemName',TestColumn) References Code(CodeSystem,CodeValue);

and:

ALTER TABLE TestTable
ADD CONSTRAINT TestConstraint
CHECK (TestColumn IN (SELECT CodeValue FROM Code WHERE CodeSystem='FixedSystemName'));

Will we have to resort to a TRIGGER to perfrom this check or is there a way to define this as a standard referential integrity check?

What will be the preformance impacts of a TRIGGER check that looks like the second of the attempts we made above?

PART 2: If the Code table contained a unique row identifier (probably assigned from via a SEQUENCE) with its own unique index and the TestColumn value was linked to the Code table via such an identifier instead of the 2-column CodeSystem-CodeValue pair, would it be easier to define a valid referential integrity check? We could live with that solution too. Received on Thu Aug 23 2001 - 08:01:51 CDT

Original text of this message

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