Why are you trying to stuff all the different types of records into one table?

I suspect you have a situation similar to the following:

  1. I have pharmaceutical products. They have a set of attributes, plus a name and an ID.
  2. I have services. They have a different set of attributes, plus a name and an ID.
  3. I have lineitems. They need to FK to a given product, but one lineitem might be for a pharmaceutical and another for a service.

I created three tables. One is a general product table. It contains the name, ID, and any other common attributes. The others are detail tables. Every single row in the product table corresponds to a given detail table.

Now, you're looking at this and saying "What if I want every detail about every single product? That's a ton of outer joins!". And, you'd be right. But, my experience is that I already know if I want pharmaceuticals or services. I almost never want to pull both at the same time. If I do, it's usually just pulling the name (which is on the product table). If I want to drill down, I can do so.

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

I shouldn't have to say this, but any code, unless otherwise stated, is untested


In reply to Re: (OT) Database design: omitted partially filled fields. by dragonchild
in thread (OT) Database design: omitted partially filled fields. by BUU

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.