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

http://msdn.microsoft.com/en-us/library/cc280372.aspx

No comments:

Post a Comment

Loop Engineering: Designing the Systems That Prompt Your Agents

Loop Engineering For the last couple of years, the core skill in working with AI was writing a good prompt. You'd craft careful instru...