Tuesday, June 28, 2011

A column may have null values. But I want to ensure that all not null values are UNIQUE.

A UNIQUE constraint is not useful here because, it will allow a single NULL value in the column, no DUPLICATE NULLs.

Use  a filtered index here :
CREATE UNIQUE INDEX indexName ON tableName(columnNames) WHERE columnName IS NOT NULL


No comments:

Post a Comment