Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> comp.databases.theory -> Re: Database design question

Re: Database design question

From: David Fetter <david_at_fetter.org>
Date: Tue, 27 Jun 2006 19:38:28 -0500
Message-ID: <mbCdncQ2irAZUjzZnZ2dnUVZ_q-dnZ2d@speakeasy.net>


sreedhardasi_at_gmail.com 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:

CREATE TABLE foo (

    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. ;)

Cheers,
D

-- 
David Fetter <david@fetter.org> http://fetter.org/
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.
                                       Kernighan
Received on Tue Jun 27 2006 - 19:38:28 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US