db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John English <john.fore...@gmail.com>
Subject Unique constraints and nulls
Date Wed, 14 May 2014 13:52:04 GMT
I have a table with two columns whose combined value I want to be unique:

   create table Foo (
     A integer,
     B integer,
     primary key(A),
     unique(A,B)
   );

This works fine except when B is null, when I can have multiple rows containing 
identical values of the form (A,null).

Is there an easy way to constrain the values of A to be unique even when B is 
null? (I could try to change things so that empty strings are used instead of 
nulls, but that would involve changing existing code and it will take quite a 
bit of work to ensure that there aren't any unexpected knock-on effects, so I 
prefer to stick with nulls if I can.)

TIA,
-- 
John English

Mime
View raw message