Adding a unique constaint to a column that allows nulls

by Scott 1. April 2010 19:06

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.

Tags:

General

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



About the author

Hi, I'm Scott.  My company develops in C#/ASP.NET/Silverlight and and creates e-commerce web sites for small business.  Visit our corporate site, Gildner Solutions.  We are working on a brand new one now.

RecentComments

Comment RSS