Unix Technical Forum

Re: UNIQUE KEY vs NULLs

This is a discussion on Re: UNIQUE KEY vs NULLs within the MySQL General forum forums, part of the MySQL category; --> > I have an InnoDB table similar to this: > > CREATE TABLE Target > (IMSI VARCHAR(15) ASCII, > ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 05:24 AM
Martijn Tonies
 
Posts: n/a
Default Re: UNIQUE KEY vs NULLs


> 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? :-)


A feature. NULL isn't equal to NULL.

> If it is a feature, than how can I assure uniqueness for a table in a

sense
> that won't allow such duplicates?


If you don't want to have NULL, use a "primary key" instead
of a "unique key".


Martijn Tonies
Database Workbench - development tool for MySQL, and more!
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:24 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com