Re: Database design question

From: David Fetter <>
Date: Tue, 27 Jun 2006 19:38:28 -0500
Message-ID: <> wrote:
> I have a database design questions. How can we specify one of two
> columns in a table should be not null? In other words, if one
> column is null then another column should not be null.

In general, you should be able to use a CHECK constraint, something like this:


    bar INTEGER,
    baz INTEGER,
    CHECK (

        (CASE WHEN bar IS NULL THEN 0 ELSE 1 END) +
        (CASE WHEN baz IS NULL THEN 0 ELSE 1 END) 
        = 1


I can't really speak to the particular design, and very likely somebody will take me to task for failure to scream about how NULLs don't belong in any design. ;)


David Fetter <>
phone: +1 415 235 3778        AIM: dfetter666
                              Skype: davidfetter

Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it.
Received on Wed Jun 28 2006 - 02:38:28 CEST

Original text of this message