top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

SQLSERVER: Column with distinct value but mulitple NULL value?

+4 votes
83 views

I have a requirement in which a column in the table should have distinct values but it may have multiple null values. How can I achieve that?

posted Feb 18, 2014 by Atul Mishra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+3 votes

In SQL Server 2008, you can define a unique filtered index based on a predicate that excludes NULLs:

CREATE UNIQUE NONCLUSTERED INDEX idx_yourcolumn_notnull
ON YourTable(yourcolumn)
WHERE yourcolumn IS NOT NULL;
In earlier versions, you can resort to VIEWS with a NOT NULL predicate to enforce the constraint.

answer Feb 19, 2014 by Asmita Agrawal
Similar Questions
+1 vote

I have created two list boxes.
listbox1 has single selection and listbox 2 has multi-selection and 3 text-boxes. I want to insert the selected items from both list-boxes as well as data entered from text-boxes at same time. I mean same statement insert using c#.

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...