I have some data I'm going to be parsing to store in a database. This data has a dozen to two dozen fields. The problem is that not every "record" has all of these fields, so one record might have 12 fields, and the next one only has 5 and the next has 24. So my problem is, how should I design a table to accomodate this?


Option 1: The first thought is to keep it simple, simply create a table with the thirty odd columns that can actually appear in the data and then leave the fields null if the data doesn't provide it.

Having 30+ columns in a RDBMS just seemed like a bad design to me though, so I'm unsure if this is a good idea. I can't really quote anything concrete either way, but this just "Feels" wrong.


Option 2: The second thought was to have two tables. The first table would have all of the data that every record posesses, and the second table would basically have 3 columns: belongs-to, type, value, so I could record all of the extra data there.

I'm sure I've seen people recomend against this strategy however, and it also feels kind of nasty.


Option 3: Again make a table that just has columns for the data that every record has, but add an extra column to store a seralized perl datastructure that contains the extra data for a particular record.

Again this seems like a bad idea because then the database can't natively access this extra data, with all the problems that entails.


So none of the solutions "feel" very good, which is why I come here. Is one of these solutions better than the others, good enough to use? Or is there a better way to solve this problem?

In reply to (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.