SQL Server Multiple null values

I was asked in an interview...
"Suppose u have a field with UNIQUE KEY. can u leave two or more cells NULL in SQL Server 2005...If Yes then Why...if NOT then Why.....

Questions by tarun_2398

Showing Answers 1 - 24 of 24 Answers

No, it can not have multiple NULL value Bcos, uniqe key insist the unique value in the coloumn But suppose you have more thn one NULL value than they will be duplicate and unique key does not give you permition two add duplicate value.

  Was this answer useful?  Yes

chihoo2003

  • Jan 9th, 2008
 

The question is somewhat different!!!!

In sql server NULL value treated as infinite, where no two NULL values are equal. So in this case we require ISNULL function.

In the case of unique constraint, here the column with unique constraint have capable to keep single null value. Multiple null values are permitted in that column. (But Orcale support it)  

  Was this answer useful?  Yes

In a unique column there is only one null value can be added. Although every null value is different in SQL Server. SQL Server itself maintain each null value by adding some prefix. So if the column is not unique there  may be multiple null value but each null value are different internally. To avoid complexity SQL Server equal a null value to another null value. So unique column can contain only one null value.

  Was this answer useful?  Yes

nirajkvinit

  • Dec 17th, 2008
 

Yes! We can have multiple values in a unique key based column. Because Null mean unspecified/undefined value. Which means, no two null values are the same.

  Was this answer useful?  Yes

slimtech

  • Feb 27th, 2009
 

In case of SQL Server : No and so is for DB2. But in case of Oracle : Yes.. Oracle supports multiple null values in the unique key column whereas SQL Server allows only one null value in the unique key column..

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions