Re: Unique Keys

From: Mikito Harakiri <mikharakiri_nospaum_at_yahoo.com>
Date: 25 Nov 2004 22:56:18 -0800
Message-ID: <8a529bb.0411252256.4f2afbdf_at_posting.google.com>


"Tony Andrews" <andrewst_at_onetel.com> wrote in message news:<1101387601.990897.214300_at_f14g2000cwb.googlegroups.com>...
> a unique constraint isn't primitive, it is a
> shorthand for a constraint that could be more generally expressed as:
>
> (select 0 from the_table t1, the_table t2
> where t1.primary_key != t2.primary_key
> and t1.unique_key = t2.unique_key)
> ={}

"primary_key" is a typo right? You probably have meant:

select 0 from the_table t1, the_table t2

where t1.unique_key = t2.unique_key
and ( t1.col1 != t2.t1.col1 
or    t1.col2 != t2.t1.col2 
or    ....)

={}

2 more cents. This definition is fine for sets but doesn't work for bags. Surprisingly bag definition is more elegant:

select 0 from the_table
group by unique_key
having count(1) > 1
= {} Received on Fri Nov 26 2004 - 07:56:18 CET

Original text of this message