|
|||||||||||
|
Re: [NOVICE] Setting a FK to look at only selected rows in the 'look-up' table...
From: Greg Cocks <gcocks(at)stoller.com>
Date: Fri Dec 28 2007 - 20:50:23 EST
-----Original Message-----
"Greg Cocks said"
| |Instead of storing the depth_unit in d_borehole, store depth_unit_id. | |Then it would be something like: | |alter table d_borehole add constraint unit_type_fk |(depth_unit_id) references r_unit (unit_id); | |unit_id will need to be the primary key (or at least unique) in r_unit. | |That is pretty much the standard way to use lookup tables. Don't storethe |lookup value anywhere except the lookup table. Anywhere else you want |that lookup value, store the primary key from the lookup table, then |when you need the text 'look it up'. |HTH. Jeff, Thanks for the reply... I think I am missing something - sorry... It seems that is the way I have it now - i.e., 'depth_unit' == 'unit_id' (sic), where the later is the PK in the look up table <r_unit> That is, the names are just different - maybe they should not be? If I normalized (sic?) it by using, say, an integer for the unit_id I both places it seems to me that there would still be the same issue of how to parse the values 'available' through the FK from <r_unit> to be *only* be those where the unit_type = 'length' in <r_unit> i.e.: SELECT r_unit.unit_id FROM r_unit WHERE r_unit.unit_type)='length'; Note that another data table might, say, only be "allowed" to use unit_type = 'velocity' Aside - I like using the abbreviated and yet unique values for the unit identifier - ft, m, ppm, ppb, etc - as the 'raw' data table seems that much more readable - and I don't appear to be causing any issues - do I need to be corrected on this approach? :-)
Cheers:
---------------------------(end of broadcast)---------------------------TIP 5: don't forget to increase your free space map settings Received on Fri Dec 28 20:53:23 2007 This archive was generated by hypermail 2.1.8 : Thu Jun 19 2008 - 00:04:49 EDT |
||||||||||
|
|||||||||||