Image

Imagebanana wrote in Imagesqlserver

Constraints

Is there a way to get SQLServer to recognise that unique constraints don't apply to nulls? For example:
create table Blah
(
  Id integer primary key,
  Token char(16) null unique
)
go
insert into Blah values (1, '1234567890abcdef')
go
insert into Blah values (2, null)
go
insert into Blah values (3, null)

"Violation of UNIQUE KEY constraint 'UQ__Blah__61274A53'. Cannot insert duplicate key in object 'Blah'."
This works fine in other databases: null is not equal to null.