Monday, May 20, 2013

Insert multiple null values in Unique key index column

hello friends,

 

Here i am sharing scripts which can be useful to us in our developement

 

CREATE TABLE [dbo].[testUnique](

      [col1] [varchar](50) NULL,

      [ID] [int] IDENTITY(1,1) NOT NULL,

) ON [PRIMARY]

 

CREATE UNIQUE INDEX IX_testUnique ON testUnique(col1)

WHERE col1 IS NOT NULL –-Here we can set any value to which we want to allow multiple value

 

Insert into testUnique(col1)

values ('a'),(null),(null)

ITWORLD
If you have any question then you put your question as comments.

Put your suggestions as comments