top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

SQLSERVER: Column with distinct value but mulitple NULL value?

+4 votes
390 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#.

...