Comments on: Referential Integrity with Virtual Columns Friends of Oracle and Java Wed, 24 Jun 2015 09:59:44 +0000 hourly 1 By: Alex Nuijten Wed, 16 Jul 2008 13:44:51 +0000 Thank you all for your comments. The suggestion done by Lucas and Nigel, I placed in a new post:

By: Nigel Thomas Tue, 15 Jul 2008 15:44:24 +0000 A common case for using a virtual column in a foreign key would be to enforce “generic foreign keys” – for example to the well known Oracle Designer CG_REF_CODES table.

create table CG_REF_CODES
( DOMAIN varchar2(20) not null
, LOW_VALUE varchar2(30) not null
, DESCRIPTION varchar2(100)
, …

For each referencing column we can define a virtual column that will be a constant (containing the value to match to CG_REF_CODES.DOMAIN).

So now we should be able to create a valid foreign key and not be concerned that there may be multiple rows in CG_REF_CODES with the same VALUE but different DOMAIN.

(Sorry, can’t test this out as I don’t have 11g installed on the laptop)

Regards Nigel

By: Lucas Jellema Tue, 15 Jul 2008 14:32:37 +0000 Could a Foreign Key also link to a Virtual Column (on which a Unique constraint is based)? That would allow the creation of Foreign Keys from say INSURANCE_POLICY explicitly to CAR when the CAR records are in a more general table that contains VEHICLES (or MEANS_OF_TRANSPORTATION).

regards, Lucas

By: Alex Nuijten Tue, 15 Jul 2008 12:52:42 +0000 Maybe I misheard him, but I’m pretty sure he said something along these lines.

By: Peter Boekelaar Tue, 15 Jul 2008 12:21:37 +0000 Hi Alex,

First of all, interesting stuff, as always.
You already wrote that the example was a bit dodgy, but could you give an example where you should/could actually use a foreign key created on a virtual column? Isn’t it a bit dangerous to make a referenence using concatenated (or changed in any matter) data?
A constraint like a unique key would be more applicable on a virtual column than a referential key…

By: Marco Gralike Tue, 15 Jul 2008 12:13:29 +0000 Sound premature…”He started by saying the Oracle 11g Release 2 can be expected the end of this calender year. “