RE: Foreign key constraints with constant values?

  • From: "Bobak, Mark" <Mark.Bobak@xxxxxxxxxxxx>
  • To: "orasnita@xxxxxxxxx" <orasnita@xxxxxxxxx>, "oracle-l@xxxxxxxxxxxxx" <oracle-l@xxxxxxxxxxxxx>
  • Date: Sun, 24 Oct 2010 05:25:25 -0400

Hi Octavian,

I'm not sure I understand the intent in your second example below, however, if 
you want to check a column value against a specific constant value (or list of 
constant known values), you should use a CHECK constraint, rather than a 
FOREIGN KEY constraint.

In general, if you have a static list of constant values, it may make more 
sense to use a CHECK constraint.  In the event of a dynamic, and possibly 
changing list of valid values, it may make more sense to use a table and a 
FOREIGN KEY constraint.

Hope that helps,

-Mark
________________________________________
From: oracle-l-bounce@xxxxxxxxxxxxx [oracle-l-bounce@xxxxxxxxxxxxx] On Behalf 
Of Octavian Rasnita [orasnita@xxxxxxxxx]
Sent: Saturday, October 23, 2010 14:14
To: oracle-l@xxxxxxxxxxxxx
Subject: Foreign key constraints with constant values?

Hi,

I have made the following table:

create table client(
id integer not null,
name varchar2(200),
type1 integer not null,
type2 integer not null,
foreign key (type1, type2) references constants(id, type)
);

It works fine, but the column type2 contains a unique value in all the records.
Is it possible to drop that column and use the constant value from it in the 
foreign key reference directly?

I have tried the following, but it gave an error:

create table client(
id integer not null,
name varchar2(200),
type1 integer not null,
foreign key (type1, 1) references constants(id, type)
);

Thanks.

Octavian

--
//www.freelists.org/webpage/oracle-l




--
//www.freelists.org/webpage/oracle-l


Other related posts: