2

I have used this on my table

alter table Draftsmen
  ADD constraint uc_draftsmen UNIQUE([DraftsmanCNICNo])

It works but it also doesn't allow NULL values to be repeated since it's a unique constraint.

I want to allow NULL to be repeated. How to do in this constraint?

sqluser
  • 5,502
  • 7
  • 36
  • 50
Cuckoo
  • 177
  • 1
  • 2
  • 10
  • Possible duplicate of [How to create a unique index on a NULL column?](http://stackoverflow.com/questions/191421/how-to-create-a-unique-index-on-a-null-column) – Breeze Apr 09 '16 at 08:41

1 Answers1

1

Standard SQL allows that but in SQL Server, you cannot do that.

Instead in SQL Server 2008 and above, you can create a unique filtered index and exclude NULLs

CREATE UNIQUE NONCLUSTERED INDEX Idx_columnName
ON tableName(columnName)
WHERE columnName IS NOT NULL
sqluser
  • 5,502
  • 7
  • 36
  • 50