Re: Mixed, or conditional, datatypes

From: Bob Badour <bbadour_at_pei.sympatico.ca>
Date: Sun, 25 Mar 2007 13:23:10 GMT
Message-ID: <2JuNh.14929$PV3.154334_at_ursa-nb00s0.nbnet.nb.ca>


sinister wrote:

> Example: suppose I'm storing responses to a diagnostic interview. One of
> the questions asked of the subject is something like
>
> 7. Have you always lived in the US?
>
> 7a. If the answer to 7 is "no," how many years have you lived in the US?
>
> What I'm wondering is, what's a good way to code this in a relational
> database?
>
> If I use one field, I could code as an integer, with -1 reserved if the
> answer to 7 is "yes", but that seems kludgey.
>
> I could use two fields, the first a boolean for 7, and the second an integer
> for 7a, but then the table is in some sense redundant: the fields are
> connected by the logic "if 7 is true, then 7a is NULL (or has no meaning
> even if assigned)". That doesn't seem all that clean either.

The truth of the matter is you really have two surveys; even though, someone presented the surveys to respondents as a union of all the questions. Lifelong residents answer one survey and part time residents answer another.

 From the above observations, the design seems obvious: Use two relations. Received on Sun Mar 25 2007 - 15:23:10 CEST

Original text of this message