Unique constraint for the columns does not work when one of values is null.

I have a table with a unique constraint on two integer columns.
Works fine, but one of the two columns can be null and then the
constraint does not work.
1 2 : OK
1 3 : OK
1 2 : error
2 null : OK
2 null : OK -> I want this to result in an error

Pugi!
puginews [ Fr, 14 September 2007 12:55 ] [ ID #1820645 ]

Re: Unique constraint for the columns does not work when one of values is null.

On 14 Sep, 11:55, Pugi! <pugin... [at] gmail.com> wrote:
> I have a table with a unique constraint on two integer columns.
> Works fine, but one of the two columns can be null and then the
> constraint does not work.
> 1 2 : OK
> 1 3 : OK
> 1 2 : error
> 2 null : OK
> 2 null : OK -> I want this to result in an error
>
> Pugi!

Do not multi-post. Cross-post if you must but don't multi post It
wastes
people's time. http://www.blakjak.demon.co.uk/mul_crss.htm
Captain Paralytic [ Fr, 14 September 2007 17:11 ] [ ID #1820654 ]
PHP » alt.php.sql » Unique constraint for the columns does not work when one of values is null.

Vorheriges Thema: session_start problem in php5
Nächstes Thema: How to enforce an ENUM ?