Click here to Skip to main content
12,240,822 members (55,479 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL-Server
Hi friends.
Is Unique key accept null value. In my application it does not accept multiple null value.but from i studied it accept null for unique column.suppose it accept, how can i modify my unique column table for accepting null value

Advance Thanks
Posted 3-Nov-12 22:58pm
Edited 3-Nov-12 23:02pm
v3
Comments
Abhishek Pant 4-Nov-12 4:27am
   
Will you eloborate what type of unique key you used a primary key or unique key.... in case of unique key 1 null value is accepted for every row and column. while in case of primary key no null values are accepted.if you built a primary key then||alter table <table name> drop constraint constraint_name Primary key(column_name)
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Logically, any key which is allowed to contain non duplicate (unique) values is a unique key, NULL is a permissible value in SQL Server , so it can have NULL for a single time just like any other value.

But as per standards, there is no such rule that only ONE NULL is allowed. So, with SQL Server you are stuck with just one time NULL value.
Refer:
http://en.wikipedia.org/wiki/Unique_key[^]
http://connect.microsoft.com/SQLServer/feedback/details/299229/change-unique-constraint-to-allow-multiple-null-values[^]
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

If you mean on a primary key column, then no - you can't have null primary keys.

If you mean a unique index on a nullable column, well...not really a good idea...but...it is possible.

Have a look here: http://sqlservercodebook.blogspot.co.uk/2008/04/multiple-null-values-in-unique-index-in.html[^]
  Permalink  
Comments
Sandeep Mewara 4-Nov-12 4:24am
   
Yeah, but there is a limitation/issue with SQL Server with multiple NULL values.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 4 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100