Adding a unique constaint to a column that allows nulls

I have an integer column in one of my database tables that allows nulls.  What I want is for any value other than nulls to be unique.  Here's how I did it:

CREATE UNIQUE NONCLUSTERED INDEX idx_SupplierID_notnull
ON Brands(SupplierID)
WHERE SupplierID IS NOT NULL; 

Brands is my table and SupplierID is the column I want to be unique.

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading