• George M Parker (12/20/2012)


    Totally disagree with the answer to the question.

    "Also, unlike PRIMARY KEY constraints, UNIQUE constraints allow for the value NULL. However, as with any value participating in a UNIQUE constraint, only one null value is allowed per column. "

    The trouble with that quotation from BoL (you should attribute what you quote, but never mind) is that it's actually wrong (like a few other things in BoL). You can demonstrate it's wrongness using the code that SQLRNNR posted earlier, or with the code snippet I use to educate people on this topic, which is if exists (select * from sys.objects where type = 'U' and name = 'k') drop table k

    create table k (a int primary key,b int, c int, unique(b,c))

    insert k values (0,0,0),(1, 1, null), (2,null,1), (3,2,null), (4,null,2),(5,3,3),(6,null,null)

    select * from sys.key_constraints where name like 'UQ__k__%'

    select * from k order by a

    drop table k

    Tom