Click here to Skip to main content
Rate this: bad
good
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 21:58pm
Edited 3-Nov-12 22:02pm
v3
Comments
Abhishek Pant at 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 at 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
0 Sergey Alexandrovich Kryukov 398
1 CPallini 333
2 George Jonsson 270
3 OriginalGriff 159
4 Prasad Khandekar 135
0 OriginalGriff 4,613
1 CPallini 3,340
2 Sergey Alexandrovich Kryukov 2,771
3 George Jonsson 2,254
4 Gihan Liyanage 2,020


Advertise | Privacy | Mobile
Web01 | 2.8.140905.1 | Last Updated 4 Nov 2012
Copyright © CodeProject, 1999-2014
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