View Single Post

   
  #1 (permalink)  
Old 02-28-2008, 05:24 AM
Dan Buettner
 
Posts: n/a
Default Re: UNIQUE KEY vs NULLs

This is a feature - a NULL value is an undefined value, therefore two
NULL values are not the same. Can be a little confusing but makes
sense when you think about it.

A UNIQUE index does ensure that non-NULL values are unique; you could
specify that your column not accept NULL values.

Dan


On 12/11/06, imre@u-tx.com <imre@u-tx.com> wrote:
> Hi,
>
> I have an InnoDB table similar to this:
>
> CREATE TABLE Target
> (IMSI VARCHAR(15) ASCII,
> IMEI VARCHAR(15) ASCII,
> UNIQUE KEY (IMSI, IMEI));
>
> After playing a bit with it, I managed to add duplicate records, if one of
> the fields was a NULL:
>
> +-----------------+-----------------+
> | IMSI | IMEI |
> +-----------------+-----------------+
> | NULL | 35195600126418 |
> | NULL | 35195600126418 |
> +-----------------+-----------------+
>
>
> Is this a bug, or a feature? :-)
>
> If it is a feature, than how can I assure uniqueness for a table in a sense
> that won't allow such duplicates?
>
> Thx
>
> ImRe
>
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=drbuettner@gmail.com
>
>

Reply With Quote