DotNet Mirror
  DNM facebook   DNM Google+   DNM Twitter   

Does UNIQUE KEY supports more than one NULL Value?

By Ashok Nalam on 12 Dec 2012 | Category: SQL Server | Tagged: Constraints unique key 
  Discuss Add Comment   |  
Add rating Rate this resource   

No. In SQL server we can insert only one NULL value to column which has UNIQUE KEY constraint.

Example:

CREATE TABLE SamepleUnique
(
Id INT PRIMARY KEY,
Name varchar(20) UNIQUE
)
INSERT INTO SamepleUnique VALUES(1,'Ram')
INSERT INTO SamepleUnique VALUES(2,'Krish')
INSERT INTO SamepleUnique VALUES(3,Null)
INSERT INTO SamepleUnique VALUES(4,Null) --Error as Violation of UNIQUE KEY constraint 'UQ__SamepleU__737584F603317E3D'. Cannot insert duplicate key in object 'dbo.SamepleUnique'.
--The statement has been terminated.


  Discuss Add Comment    
Add rating Rate this resource   
About the Contributor
Member Since : 10 Dec 2012
Member Points (Level) : 9526  (Professional)
Location : INDIA
Home Page : http://dotnetmirror.com
About : I am admin of this site.
Rate this resource
 
Add your Comment
Name Email WebSite
Captcha Refresh


Comments (1)
 
1. By Karna on 28 Dec 2012

Uniuqe Key--Accepts any value exactly once in a column including Null Primary Key--Accepts any value exactly once in a column excluding Null

 
cheap jordans|wholesale air max|wholesale jordans|wholesale jewelry|wholesale jerseys