Comments on: Referential Integrity with Virtual Columns https://technology.amis.nl/2008/07/15/referential-integrity-with-virtual-columns/ Friends of Oracle and Java Thu, 23 Apr 2015 12:54:46 +0000 hourly 1 http://wordpress.org/?v=4.2 By: Alex Nuijten https://technology.amis.nl/2008/07/15/referential-integrity-with-virtual-columns/#comment-5407 Wed, 16 Jul 2008 13:44:51 +0000 http://technology.amis.nl/blog/?p=3322#comment-5407 Thank you all for your comments. The suggestion done by Lucas and Nigel, I placed in a new post: http://technology.amis.nl/blog/?p=3325

]]>
By: Nigel Thomas https://technology.amis.nl/2008/07/15/referential-integrity-with-virtual-columns/#comment-5406 Tue, 15 Jul 2008 15:44:24 +0000 http://technology.amis.nl/blog/?p=3322#comment-5406 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 https://technology.amis.nl/2008/07/15/referential-integrity-with-virtual-columns/#comment-5405 Tue, 15 Jul 2008 14:32:37 +0000 http://technology.amis.nl/blog/?p=3322#comment-5405 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 https://technology.amis.nl/2008/07/15/referential-integrity-with-virtual-columns/#comment-5404 Tue, 15 Jul 2008 12:52:42 +0000 http://technology.amis.nl/blog/?p=3322#comment-5404 Maybe I misheard him, but I’m pretty sure he said something along these lines.

]]>
By: Peter Boekelaar https://technology.amis.nl/2008/07/15/referential-integrity-with-virtual-columns/#comment-5403 Tue, 15 Jul 2008 12:21:37 +0000 http://technology.amis.nl/blog/?p=3322#comment-5403 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 https://technology.amis.nl/2008/07/15/referential-integrity-with-virtual-columns/#comment-5402 Tue, 15 Jul 2008 12:13:29 +0000 http://technology.amis.nl/blog/?p=3322#comment-5402 Sound premature…”He started by saying the Oracle 11g Release 2 can be expected the end of this calender year. “

]]>