Who knows how to create unique constraint for set of 2 columns with NULLS allowed in both columns? I mean ignore uniqueness for col1=NULL AND col2=NULL, but let constraint work in case of only one of them s NULL? I found how to do it for single column (How do I create a unique constraint that also allows nulls?), but can not make it for 2 columns. Here is my script which works for existing records (multiple NULL, NULL is allowed), but does not let add any new NULL, NULL record:
CREATE UNIQUE NONCLUSTERED INDEX MyIndex ON dbo.MyTable(col1, col2)
WHERE col1 IS NOT NULL AND col2 IS NOT NULL
UPDATE: Well, it lets you add new (NULL, NULL) values so I was wrong, however it also lets you add something like (1, NULL), (1, NULL) which I would NOT like to be, so uniqueness should work for this case, only multiple (NULL, NULL) should be allowed. How to do this?