Re: supersunday modeling question
Date: 5 Feb 2007 12:59:48 -0800
Message-ID: <1170709188.757121.150800_at_s48g2000cws.googlegroups.com>
On Feb 5, 4:51 am, "foothillbiker" <foothillbi..._at_gmail.com> wrote:
> All,
>
> Suppose I have a table like this:
>
> 15:14:55 system_at_ta64 SQL> desc rowshambow
> Name Null? Type
> ----------------------------------------- --------
> ----------------------------
> ROWSHAMBOWID NOT NULL NUMBER
> ROCKID NUMBER
> PAPERID NUMBER
> SCISSORSID NUMBER
>
> rockid/paperid/scissorsid are all foreign keys to rocktable/
> papertable/
> scissorstable, respectively.
>
> The biz requirements are that every record in the table must have
> exactly one (1) of these three fields populated.
>
As Bob indicated, you should consider normalizing your design. Meanwhile you could do something like:
CHECK ((case when ROCKID IS NOT NULL then 1 else 0 end +
case when PAPERID IS NOT NULL then 1 else 0 end + case when SCISSORSID IS NOT NULL then 1 else 0 end ) =1)
/Lennart
[...] Received on Mon Feb 05 2007 - 21:59:48 CET