Click here to Skip to main content
11,495,758 members (63,884 online)
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 22:58pm
Edited 3-Nov-12 23: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 Dnyaneshwar@Pune 692
1 CHill60 318
2 Sascha Lefèvre 245
3 RyanDev 230
4 Sergey Alexandrovich Kryukov 185
0 Sergey Alexandrovich Kryukov 10,362
1 OriginalGriff 8,821
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 4 Nov 2012
Copyright © CodeProject, 1999-2015
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