Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

foreign key, or "in" constraint?

 
   Database Help (Home) -> Oracle RSS
Next:  reads and segments  
Author Message
mh

External


Since: Jan 09, 2008
Posts: 124



(Msg. 1) Posted: Mon Oct 06, 2008 5:26 pm
Post subject: foreign key, or "in" constraint?
Archived from groups: comp>databases>oracle>misc (more info?)

Suppose you have a table with a status column, and
the status can be one of "queued", "inprogress",
"failed", or "completed".

This can be enforced two ways:

1. status has a FK to a "statuses" table, and the allowed statuses
are in that table.

2. with a constraint such as
status in ('queued','ip','failed','completed')

Which is more typically used? What are the pros and cons,
tradeoffs, etc, of each?

Many TIA!
Mark

--
Mark Harrison
Pixar Animation Studios

 >> Stay informed about: foreign key, or "in" constraint? 
Back to top
Login to vote
Mark D Powell

External


Since: Dec 20, 2007
Posts: 259



(Msg. 2) Posted: Mon Oct 06, 2008 5:26 pm
Post subject: Re: foreign key, or "in" constraint? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Oct 6, 4:39 pm, m... RemoveThis @pixar.com wrote:
> Suppose you have a table with a status column, and
> the status can be one of "queued", "inprogress",
> "failed", or "completed".
>
> This can be enforced two ways:
>
> 1.  status has a FK to a "statuses" table, and the allowed statuses
>     are in that table.
>
> 2.  with a constraint such as
>         status in ('queued','ip','failed','completed')
>
> Which is more typically used?  What are the pros and cons,
> tradeoffs, etc, of each?
>
> Many TIA!
> Mark
>
> --
> Mark Harrison
> Pixar Animation Studios

The pros of the column constraint approach is you do not need a second
table.

The cons of the column constraint approach is that the values are
basically hard coded and if you need to apply the same restriction to
another table you now have two or more places that have to be changed
in the event you add or remove another value.

I think the key questions are: How likely are the values to every
change and on how many different tables would you need to actually
check that the value is valid? The closer the anwers are to never and
one the more applicable the column constraint is.

HTH -- Mark D Powell --

 >> Stay informed about: foreign key, or "in" constraint? 
Back to top
Login to vote
Malcolm Dew-Jones

External


Since: Aug 05, 2003
Posts: 300



(Msg. 3) Posted: Mon Oct 06, 2008 5:26 pm
Post subject: Re: foreign key, or "in" constraint? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Mark D Powell (Mark.Powell@eds.com) wrote:
: On Oct 6, 4:39=A0pm, m... DeleteThis @pixar.com wrote:
: > Suppose you have a table with a status column, and
: > the status can be one of "queued", "inprogress",
: > "failed", or "completed".
: >
: > This can be enforced two ways:
: >
: > 1. =A0status has a FK to a "statuses" table, and the allowed statuses
: > =A0 =A0 are in that table.
: >
: > 2. =A0with a constraint such as
: > =A0 =A0 =A0 =A0 status in ('queued','ip','failed','completed')
: >
: > Which is more typically used? =A0What are the pros and cons,
: > tradeoffs, etc, of each?
: >
: > Many TIA!
: > Mark
: >
: > --
: > Mark Harrison
: > Pixar Animation Studios

: The pros of the column constraint approach is you do not need a second
: table.

: The cons of the column constraint approach is that the values are
: basically hard coded and if you need to apply the same restriction to
: another table you now have two or more places that have to be changed
: in the event you add or remove another value.

: I think the key questions are: How likely are the values to every
: change and on how many different tables would you need to actually
: check that the value is valid? The closer the anwers are to never and
: one the more applicable the column constraint is.

: HTH -- Mark D Powell --

If you need to read the values then the FK can be useful.

For example a report that summarizes the data by status needs to loop over
the FK table because otherwise it can't report on a status that has no
entries - unless you hard code the possible values into the report logic.

Same issue in a data entry form, if you don't have an FK table then how do
you build an LOV to select the status ? -- you have to hard code the
values in the LOV if you don't have a list to read.

$0.10
 >> Stay informed about: foreign key, or "in" constraint? 
Back to top
Login to vote
mh

External


Since: Jan 09, 2008
Posts: 124



(Msg. 4) Posted: Wed Oct 08, 2008 8:25 pm
Post subject: Re: foreign key, or "in" constraint? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks Mark and Malcolm,
That really clarified my thinking.

--
Mark Harrison
Pixar Animation Studios
 >> Stay informed about: foreign key, or "in" constraint? 
Back to top
Login to vote
Display posts from previous:   
   Database Help (Home) -> Oracle All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]