Databases
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives FAQs Databases

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old June 18th, 2008, 07:50 PM
Frank Swarbrick
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
"code" tables?

The following is a message from a fellow programmer to a group of use that
are involved in table design:

"We are planning on creating 'account opening sources' lookup table to store
'account source' codes and corresponding descriptions. Problem with storing
this data in a dedicated table is that as we go on we'd end up with tens and
possibly hundreds of lookup tables.

I suggest that instead we create a more generic table that stores various
codes used within a schema, along with corresponding description and a code
'category'. Another table (optional but recommended) would contain
'category' descriptions.

This is not my idea, I've seen this approach used at other companies.
Please see attached for an illustration.
Let me know what you think."

I'd like to know how other companies do this. Do you have a separate table
for each set of codes or do you have one table with basically three columns:
code_category, code_value, code_description (or just catagory, value,
description)?

Thanks for any insight.

Frank


Reply With Quote
  #2  
Old June 19th, 2008, 06:31 AM
Marco Mariani
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
"code" tables?

Frank Swarbrick wrote:

This is not my idea, I've seen this approach used at other companies.
Please see attached for an illustration.
Let me know what you think."
>

I'd like to know how other companies do this. Do you have a separate table
for each set of codes or do you have one table with basically three columns:
code_category, code_value, code_description (or just catagory, value,
description)?

The "one big Entity-Attribute-Value table" is a well-known DB
anti-pattern, i.e. a common mistake.

It _might_ make sense sometimes, but most of the times it doesn't.

Reply With Quote
  #3  
Old June 19th, 2008, 12:50 PM
--CELKO--
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
"code" tables?

>I suggest that instead we create a more generic table that stores various codes used within a schema, along with corresponding description and a code 'category'. Another table (optional but recommended) would contain 'category' descriptions. <<

The name of this design fallacy is TLT (" True Lookup Table") or
MUCK ("Massively Unified Code Keys"). You can Google around more
details or read Section 4.4 of THINKING IN SETS: AUXILIARY, TEMPRAL
AND VIRTUAL TABLES.

>This is not my idea, I've seen this approach used at other companies. <<


Me, too. I charge them $1K-2K per day to clean up stuff like this.



Reply With Quote
  #4  
Old June 20th, 2008, 11:30 PM
--CELKO--
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
"code" tables?

>For instance, the concern about someone adding a code_value that is a lot of whitespace terminated by a single space. Unless you are using a CHAR(1) field [sic: column] this is always a possibility. <<

"build it and they will come" of the evil things I do is load the
Heart Sutra into huge NVARCHAR() columns when I stress a design. If
they will not learn RDBMS, they will have a chance for
Enlightenment :)

>I'm not sure what the maximum length of the field [sic] has to do with how likely the occurrence would be. Maybev you have some sort of statistics on this? <<


Since I just started a book on industry standards, most are fixed
length strings under 25 characters -- boy, is that a generalization!


Reply With Quote
  #5  
Old June 25th, 2008, 09:50 AM
--CELKO--
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
"code" tables?

>Humans have the nearly unique ability to learn from others mistakes. You are not suggesting the NLY way to learn is to make mistakes are you? <<

If you want to learn from mistakes, let them be someone else's
mistakes! Much cheaper that way.

Reply With Quote
  #6  
Old June 27th, 2008, 06:30 AM
Marco Mariani
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
"code" tables?

David Cressey wrote:

I can't tell you the number of times programmers have come to me for help
with a query
that produces wrong results, and when I try to change their "select" to
"select distinct" to see if maybe that's the problem,

Hey, wait a minute.
Usually, it's the other way round.

Some people _always_ run DISTINCT because they are not able to "remove
duplicates" :-)


I patiently explained to them that I first want to come up with a query that
is logically correct, then if necessary, come up with one that's logically equivalent, but
runs fast.

If "fast" comes first, any program will take longer to be "correct" and
will seldom ever be "clean".

Reply With Quote
  #7  
Old June 27th, 2008, 10:30 AM
--CELKO--
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
"code" tables?

>When I see SELECT DISTINCT in anything but an ad hoc query, I know something is wrong with the query. <<

I know what you are saying, but I regard this and a few other things
as symptoms of bad SQL, not absolute proof of it. I look for a CRSS
JIN that wasn't supposed to be there. But SELECT DISTINCT can be
valid.

symptoms are the use of Rs when an IN() would work. Likewise,
failure to use BETWEEN is another symptom. These tell me he has not
un-learned his original procedural language.


Reply With Quote
  #8  
Old June 30th, 2008, 10:10 AM
--CELKO--
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
"code" tables?

>I can't help wishing that the optimizer could figure it out. But that's probably way down on the list of things an optimizer should be able to do. <<

Actually, it is not too hard to detect in many cases. If the result
set has a key in it without a cross join, then the rows are UNIQUE.
Perfect hashing and bit vector indexing can also spot and reject
redundant duplicates during processing.




Reply With Quote
Reply

Viewing: Web Development Archives FAQs Databases > "code" tables?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway