<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; Explanation about Usage of Unique Index and Unique Constraint</title>
	<atom:link href="http://blog.sqlauthority.com/2008/09/07/sql-server-explanation-about-usage-of-unique-index-and-unique-constraint/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2008/09/07/sql-server-explanation-about-usage-of-unique-index-and-unique-constraint/</link>
	<description>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:54:09 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Stan Segers</title>
		<link>http://blog.sqlauthority.com/2008/09/07/sql-server-explanation-about-usage-of-unique-index-and-unique-constraint/#comment-53954</link>
		<dc:creator>Stan Segers</dc:creator>
		<pubDate>Wed, 22 Jul 2009 11:32:09 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1039#comment-53954</guid>
		<description>Actually Microsoft SQL Server&#039;s implementation of the unique constraint does not adhere to the SQL-standard. So the fact that other databases (like Oracle, MySQL or Microsoft Access) allow multiple NULLs in a UNIQUE constraint/index shouldn&#039;t be surprising.

With SQL Server you can however work around the problem with indexed views (as of SQL Server 2000) or filtered indexes (as of SQL Server 2008).

For more details on the SQL Server bug, see https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=299229</description>
		<content:encoded><![CDATA[<p>Actually Microsoft SQL Server&#8217;s implementation of the unique constraint does not adhere to the SQL-standard. So the fact that other databases (like Oracle, MySQL or Microsoft Access) allow multiple NULLs in a UNIQUE constraint/index shouldn&#8217;t be surprising.</p>
<p>With SQL Server you can however work around the problem with indexed views (as of SQL Server 2000) or filtered indexes (as of SQL Server 2008).</p>
<p>For more details on the SQL Server bug, see <a href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=299229" rel="nofollow">https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=299229</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jose americo antoine</title>
		<link>http://blog.sqlauthority.com/2008/09/07/sql-server-explanation-about-usage-of-unique-index-and-unique-constraint/#comment-51677</link>
		<dc:creator>jose americo antoine</dc:creator>
		<pubDate>Fri, 08 May 2009 00:42:35 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1039#comment-51677</guid>
		<description>Its not possible to create unique index with more than one null value in mssql, only in oracle.
The best solution i found:
http://sqlservercodebook.blogspot.com/2008/04/multiple-null-values-in-unique-index-in.html

About the error:
An explicit DROP INDEX is not allowed on index...

Dont use the UI editor
Use query analyser to drop the constraint first:
ALTER TABLE table_name DROP CONSTRAINT FK_constraint_name
and then recreate the constraint(then you can do in the UI editor)</description>
		<content:encoded><![CDATA[<p>Its not possible to create unique index with more than one null value in mssql, only in oracle.<br />
The best solution i found:<br />
<a href="http://sqlservercodebook.blogspot.com/2008/04/multiple-null-values-in-unique-index-in.html" rel="nofollow">http://sqlservercodebook.blogspot.com/2008/04/multiple-null-values-in-unique-index-in.html</a></p>
<p>About the error:<br />
An explicit DROP INDEX is not allowed on index&#8230;</p>
<p>Dont use the UI editor<br />
Use query analyser to drop the constraint first:<br />
ALTER TABLE table_name DROP CONSTRAINT FK_constraint_name<br />
and then recreate the constraint(then you can do in the UI editor)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Amit Lohakare</title>
		<link>http://blog.sqlauthority.com/2008/09/07/sql-server-explanation-about-usage-of-unique-index-and-unique-constraint/#comment-50030</link>
		<dc:creator>Amit Lohakare</dc:creator>
		<pubDate>Thu, 26 Mar 2009 12:32:40 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1039#comment-50030</guid>
		<description>If I already have unique non cluster index made up of composite keys and if I want to add a column having multiple null values in existing index, how can I do it ?
If I try to add this column in existing index, it gives me following message:

Drop failed for Index &#039;IX_TABLE_A&#039;.  (Microsoft.SqlServer.Smo)

------------------------------
ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

------------------------------

An explicit DROP INDEX is not allowed on index &#039;dbo.TABLE_A.IX_TABLE_A&#039;. It is being used for FOREIGN KEY constraint enforcement. (Microsoft SQL Server, Error: 3723)</description>
		<content:encoded><![CDATA[<p>If I already have unique non cluster index made up of composite keys and if I want to add a column having multiple null values in existing index, how can I do it ?<br />
If I try to add this column in existing index, it gives me following message:</p>
<p>Drop failed for Index &#8216;IX_TABLE_A&#8217;.  (Microsoft.SqlServer.Smo)</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
ADDITIONAL INFORMATION:</p>
<p>An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>An explicit DROP INDEX is not allowed on index &#8216;dbo.TABLE_A.IX_TABLE_A&#8217;. It is being used for FOREIGN KEY constraint enforcement. (Microsoft SQL Server, Error: 3723)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vivek</title>
		<link>http://blog.sqlauthority.com/2008/09/07/sql-server-explanation-about-usage-of-unique-index-and-unique-constraint/#comment-45825</link>
		<dc:creator>Vivek</dc:creator>
		<pubDate>Wed, 21 Jan 2009 07:40:29 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1039#comment-45825</guid>
		<description>SET NUMERIC_ROUNDABORT OFF;
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT,
    QUOTED_IDENTIFIER, ANSI_NULLS ON;
GO
CREATE TABLE t1 (id INT, title VARCHAR(20))
GO

-- optional instead of trigger to disable the insert directly into the table
CREATE TRIGGER trg_t1_DisableInsert ON t1
INSTEAD OF INSERT
AS
BEGIN
    -- use 18 to stop further processing
    RAISERROR (40000, 18, 1, &#039;Use view dbo.v1 to insert data into table&#039;)
END
GO

CREATE VIEW v1
WITH SCHEMABINDING
AS
    SELECT id, title
    FROM dbo.t1
    WHERE id IS NOT NULL
GO
--Create an index on the view.
CREATE UNIQUE CLUSTERED INDEX CI_V1_ID 
    ON dbo.v1 (id);
GO


INSERT INTO v1 (id, title)
SELECT 1, &#039;title 1&#039; UNION ALL
SELECT 2, &#039;title 2&#039; UNION ALL
SELECT 3, &#039;title 3&#039; UNION ALL
SELECT 4, &#039;title 4&#039; UNION ALL
SELECT null, &#039;title null&#039;

-- this fails because it clashes with the clustered index on the view
INSERT INTO v1 (id, title)
SELECT 1, &#039;title 5&#039;

-- this is ok because it doesn&#039;t clash.
INSERT INTO v1 (id, title)
SELECT NULL, &#039;title 5&#039;

-- we see that the table can contain only unique values and more than one null
SELECT * FROM t1
SELECT * FROM v1

GO
DROP VIEW dbo.v1
GO
DROP TABLE dbo.t1</description>
		<content:encoded><![CDATA[<p>SET NUMERIC_ROUNDABORT OFF;<br />
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT,<br />
    QUOTED_IDENTIFIER, ANSI_NULLS ON;<br />
GO<br />
CREATE TABLE t1 (id INT, title VARCHAR(20))<br />
GO</p>
<p>&#8211; optional instead of trigger to disable the insert directly into the table<br />
CREATE TRIGGER trg_t1_DisableInsert ON t1<br />
INSTEAD OF INSERT<br />
AS<br />
BEGIN<br />
    &#8212; use 18 to stop further processing<br />
    RAISERROR (40000, 18, 1, &#8216;Use view dbo.v1 to insert data into table&#8217;)<br />
END<br />
GO</p>
<p>CREATE VIEW v1<br />
WITH SCHEMABINDING<br />
AS<br />
    SELECT id, title<br />
    FROM dbo.t1<br />
    WHERE id IS NOT NULL<br />
GO<br />
&#8211;Create an index on the view.<br />
CREATE UNIQUE CLUSTERED INDEX CI_V1_ID<br />
    ON dbo.v1 (id);<br />
GO</p>
<p>INSERT INTO v1 (id, title)<br />
SELECT 1, &#8216;title 1&#8242; UNION ALL<br />
SELECT 2, &#8216;title 2&#8242; UNION ALL<br />
SELECT 3, &#8216;title 3&#8242; UNION ALL<br />
SELECT 4, &#8216;title 4&#8242; UNION ALL<br />
SELECT null, &#8216;title null&#8217;</p>
<p>&#8211; this fails because it clashes with the clustered index on the view<br />
INSERT INTO v1 (id, title)<br />
SELECT 1, &#8216;title 5&#8242;</p>
<p>&#8211; this is ok because it doesn&#8217;t clash.<br />
INSERT INTO v1 (id, title)<br />
SELECT NULL, &#8216;title 5&#8242;</p>
<p>&#8211; we see that the table can contain only unique values and more than one null<br />
SELECT * FROM t1<br />
SELECT * FROM v1</p>
<p>GO<br />
DROP VIEW dbo.v1<br />
GO<br />
DROP TABLE dbo.t1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: safia</title>
		<link>http://blog.sqlauthority.com/2008/09/07/sql-server-explanation-about-usage-of-unique-index-and-unique-constraint/#comment-44371</link>
		<dc:creator>safia</dc:creator>
		<pubDate>Mon, 24 Nov 2008 16:08:12 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1039#comment-44371</guid>
		<description>Nice topic and discussion. Thanks to all. I have a question. I have few join tables in database such as 

user_role
user_role_ID  PK
user_id           FK
role_id            FK

where a combination of user_id and role_id is unique. Is it a good idea to build a composite unique index on those kind of join tables or it is not necessary.

Thanks.</description>
		<content:encoded><![CDATA[<p>Nice topic and discussion. Thanks to all. I have a question. I have few join tables in database such as </p>
<p>user_role<br />
user_role_ID  PK<br />
user_id           FK<br />
role_id            FK</p>
<p>where a combination of user_id and role_id is unique. Is it a good idea to build a composite unique index on those kind of join tables or it is not necessary.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Tobey</title>
		<link>http://blog.sqlauthority.com/2008/09/07/sql-server-explanation-about-usage-of-unique-index-and-unique-constraint/#comment-44290</link>
		<dc:creator>Tom Tobey</dc:creator>
		<pubDate>Wed, 19 Nov 2008 21:48:40 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1039#comment-44290</guid>
		<description>I&#039;m running into this exact problem. Thanks for the discussion. We have thousands of suppliers and not all of them use DUNS number, but when they do we keep track of it in our vendor database at Lincoln Financial Group. We have a different internalsupplierid which is unique and is the primary key. I can handle unique checking on DUNS in the application (ugh, if I have to), but it sure would be nice if on the database SQL server made it easier to add a &quot;no duplicates unless null&quot; index option.</description>
		<content:encoded><![CDATA[<p>I&#8217;m running into this exact problem. Thanks for the discussion. We have thousands of suppliers and not all of them use DUNS number, but when they do we keep track of it in our vendor database at Lincoln Financial Group. We have a different internalsupplierid which is unique and is the primary key. I can handle unique checking on DUNS in the application (ugh, if I have to), but it sure would be nice if on the database SQL server made it easier to add a &#8220;no duplicates unless null&#8221; index option.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christoph Ingenhaag</title>
		<link>http://blog.sqlauthority.com/2008/09/07/sql-server-explanation-about-usage-of-unique-index-and-unique-constraint/#comment-42903</link>
		<dc:creator>Christoph Ingenhaag</dc:creator>
		<pubDate>Wed, 17 Sep 2008 17:41:12 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1039#comment-42903</guid>
		<description>I would prefer an indexed view to enforce uniqueness on nullable columns (not in SQL Server 2008):


create view xy
with schemabinding
as
select
    uniquevalue
from dbo.table
where
    uniquevalue is not NULL

create unique clustered index cui on dbo.table(uniquevalue)

IMHO the only reasonable solution

Regards
Christop Ingenhaag</description>
		<content:encoded><![CDATA[<p>I would prefer an indexed view to enforce uniqueness on nullable columns (not in SQL Server 2008):</p>
<p>create view xy<br />
with schemabinding<br />
as<br />
select<br />
    uniquevalue<br />
from dbo.table<br />
where<br />
    uniquevalue is not NULL</p>
<p>create unique clustered index cui on dbo.table(uniquevalue)</p>
<p>IMHO the only reasonable solution</p>
<p>Regards<br />
Christop Ingenhaag</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yaakov Ellis</title>
		<link>http://blog.sqlauthority.com/2008/09/07/sql-server-explanation-about-usage-of-unique-index-and-unique-constraint/#comment-42638</link>
		<dc:creator>Yaakov Ellis</dc:creator>
		<pubDate>Wed, 10 Sep 2008 08:43:09 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1039#comment-42638</guid>
		<description>Nagaraj - this however has the same problem as originally mentioned by Bengan: &quot;&lt;em&gt;The problem of course is to find a set of deterministic data that is guaranteed to be unique for each row and at the same time guaranteed not to be present in the original column.&lt;/em&gt;&quot;.  

I think that the solution to this would be to use GUIDs (Type: UniqueIdentifier) as the datatype for the Primary Key row. This would ensure that no PK value would ever equal the unique column value. You would still have to put logic into your application to determine whether or not a real value or GUID-in-place-of-null is being used.</description>
		<content:encoded><![CDATA[<p>Nagaraj &#8211; this however has the same problem as originally mentioned by Bengan: &#8220;<em>The problem of course is to find a set of deterministic data that is guaranteed to be unique for each row and at the same time guaranteed not to be present in the original column.</em>&#8220;.  </p>
<p>I think that the solution to this would be to use GUIDs (Type: UniqueIdentifier) as the datatype for the Primary Key row. This would ensure that no PK value would ever equal the unique column value. You would still have to put logic into your application to determine whether or not a real value or GUID-in-place-of-null is being used.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nagaraj</title>
		<link>http://blog.sqlauthority.com/2008/09/07/sql-server-explanation-about-usage-of-unique-index-and-unique-constraint/#comment-42616</link>
		<dc:creator>Nagaraj</dc:creator>
		<pubDate>Wed, 10 Sep 2008 02:11:32 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1039#comment-42616</guid>
		<description>I find Bengan solution to be perfect. 

1. create a computed column.
2. Pass the &#039;unique column&#039;  value when it is not null
3. When it is null copy the Primary key&#039;s value into the computed column.
4. Set the unique constraint on computed column</description>
		<content:encoded><![CDATA[<p>I find Bengan solution to be perfect. </p>
<p>1. create a computed column.<br />
2. Pass the &#8216;unique column&#8217;  value when it is not null<br />
3. When it is null copy the Primary key&#8217;s value into the computed column.<br />
4. Set the unique constraint on computed column</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: HeatherK</title>
		<link>http://blog.sqlauthority.com/2008/09/07/sql-server-explanation-about-usage-of-unique-index-and-unique-constraint/#comment-42609</link>
		<dc:creator>HeatherK</dc:creator>
		<pubDate>Tue, 09 Sep 2008 21:19:34 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1039#comment-42609</guid>
		<description>SQL Server 2008 supports filtered indexes (WHERE clause for indexes).  Filtered indexes allow you to enforce unique constraints on nullable columns.</description>
		<content:encoded><![CDATA[<p>SQL Server 2008 supports filtered indexes (WHERE clause for indexes).  Filtered indexes allow you to enforce unique constraints on nullable columns.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yaakov Ellis</title>
		<link>http://blog.sqlauthority.com/2008/09/07/sql-server-explanation-about-usage-of-unique-index-and-unique-constraint/#comment-42586</link>
		<dc:creator>Yaakov Ellis</dc:creator>
		<pubDate>Tue, 09 Sep 2008 08:54:39 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1039#comment-42586</guid>
		<description>Sorry Imran, but I still don&#039;t see how your suggested solution enables the original poster to do what they want: have a unique constraint on one column that allows multiple null values, but ensures that all non-null values are unique.</description>
		<content:encoded><![CDATA[<p>Sorry Imran, but I still don&#8217;t see how your suggested solution enables the original poster to do what they want: have a unique constraint on one column that allows multiple null values, but ensures that all non-null values are unique.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2008/09/07/sql-server-explanation-about-usage-of-unique-index-and-unique-constraint/#comment-42575</link>
		<dc:creator>pinaldave</dc:creator>
		<pubDate>Tue, 09 Sep 2008 02:02:31 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1039#comment-42575</guid>
		<description>@Yaakov Ellis,  @Bengan and @Imran Mohammed,

I wish all of blog reader read this particular thread. This is very interesting and in depth discussion of the subject.  I really like the way all of you are participating to help community.

@Imran,

I really like your additional explanation and politeness towards other experts.

Regards,
Pinal Dave ( http://www.SQLAuthority.com )</description>
		<content:encoded><![CDATA[<p>@Yaakov Ellis,  @Bengan and @Imran Mohammed,</p>
<p>I wish all of blog reader read this particular thread. This is very interesting and in depth discussion of the subject.  I really like the way all of you are participating to help community.</p>
<p>@Imran,</p>
<p>I really like your additional explanation and politeness towards other experts.</p>
<p>Regards,<br />
Pinal Dave ( <a href="http://www.SQLAuthority.com" rel="nofollow">http://www.SQLAuthority.com</a> )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2008/09/07/sql-server-explanation-about-usage-of-unique-index-and-unique-constraint/#comment-42569</link>
		<dc:creator>Imran Mohammed</dc:creator>
		<pubDate>Tue, 09 Sep 2008 00:46:49 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1039#comment-42569</guid>
		<description>Hello all,

My first statement says... &quot;I am sure there must be another way of doing this, I would do something like this,&quot;

The question was: There is a Unique Key and this field “alow null”, but when i am going to create a Unique Key the SQLSERVER saw that there were values duplicated and the values are “nulls”.

What I understood from this question was, the column we are talking about itself is unique except the fact that it has more than one null values. Because of this we cannot create a unique constraint on that column and I believe there is no way to create a unique constraint on a column which has more than one null unless you make a composite key, to do this I suggested two ways,

1. Combine this with any other unique column. Here when I say these, I am talking for only null records, not for non null records, that wasn;t even discussed in the question. The only concern of that person was how to solve null values and still make this column unique. no where he said that he want to make this column who unique.... his concern was only for null records.

2. I suggested that he create an identity column, in case if he dont have a uniwue column. now create a composite unique constraint on previous column and newly created identity column, again the concern here was only for null values. 

I understand your concern, you are asking if I make a unique constraint, on cola and colb, colb is identity, then I can have duplicate records in cola, but the combination of cola and colb will still be unique. You are correct, but again like I said, I answered this question thinking that the problem is only with null records and column by default have only unique non null records.

I am always ready to correct myself. Thanks for bringing up this fact.

Thanks,
Imran.</description>
		<content:encoded><![CDATA[<p>Hello all,</p>
<p>My first statement says&#8230; &#8220;I am sure there must be another way of doing this, I would do something like this,&#8221;</p>
<p>The question was: There is a Unique Key and this field “alow null”, but when i am going to create a Unique Key the SQLSERVER saw that there were values duplicated and the values are “nulls”.</p>
<p>What I understood from this question was, the column we are talking about itself is unique except the fact that it has more than one null values. Because of this we cannot create a unique constraint on that column and I believe there is no way to create a unique constraint on a column which has more than one null unless you make a composite key, to do this I suggested two ways,</p>
<p>1. Combine this with any other unique column. Here when I say these, I am talking for only null records, not for non null records, that wasn;t even discussed in the question. The only concern of that person was how to solve null values and still make this column unique. no where he said that he want to make this column who unique&#8230;. his concern was only for null records.</p>
<p>2. I suggested that he create an identity column, in case if he dont have a uniwue column. now create a composite unique constraint on previous column and newly created identity column, again the concern here was only for null values. </p>
<p>I understand your concern, you are asking if I make a unique constraint, on cola and colb, colb is identity, then I can have duplicate records in cola, but the combination of cola and colb will still be unique. You are correct, but again like I said, I answered this question thinking that the problem is only with null records and column by default have only unique non null records.</p>
<p>I am always ready to correct myself. Thanks for bringing up this fact.</p>
<p>Thanks,<br />
Imran.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bengan</title>
		<link>http://blog.sqlauthority.com/2008/09/07/sql-server-explanation-about-usage-of-unique-index-and-unique-constraint/#comment-42540</link>
		<dc:creator>Bengan</dc:creator>
		<pubDate>Mon, 08 Sep 2008 11:02:00 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1039#comment-42540</guid>
		<description>Just like mr. Ellis, I fail to see how any of the two proposed solutions actually solve the original problem.

If you truly, desperately must have a column of unique non-null values but still allow many null values, one cheesy way would be to add a computed column, defined to contain the same non-null data, and some other, unique, data when the original column is null. E.g. like this:

ALTER TABLE SomeTable
 ADD DummyColumn AS CASE
   WHEN UniqueColumn IS NULL THEN SomeReallyUniqueColumnOrCombinationsThereofThatAreGuaranteedNeverToOccurInTheOtherUniqueColumn
   ELSE UniqueColumn
END PERSISTED

The problem of course is to find a set of deterministic data that is guaranteed to be unique for each row and at the same time guaranteed not to be present in the original column.</description>
		<content:encoded><![CDATA[<p>Just like mr. Ellis, I fail to see how any of the two proposed solutions actually solve the original problem.</p>
<p>If you truly, desperately must have a column of unique non-null values but still allow many null values, one cheesy way would be to add a computed column, defined to contain the same non-null data, and some other, unique, data when the original column is null. E.g. like this:</p>
<p>ALTER TABLE SomeTable<br />
 ADD DummyColumn AS CASE<br />
   WHEN UniqueColumn IS NULL THEN SomeReallyUniqueColumnOrCombinationsThereofThatAreGuaranteedNeverToOccurInTheOtherUniqueColumn<br />
   ELSE UniqueColumn<br />
END PERSISTED</p>
<p>The problem of course is to find a set of deterministic data that is guaranteed to be unique for each row and at the same time guaranteed not to be present in the original column.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yaakov Ellis</title>
		<link>http://blog.sqlauthority.com/2008/09/07/sql-server-explanation-about-usage-of-unique-index-and-unique-constraint/#comment-42522</link>
		<dc:creator>Yaakov Ellis</dc:creator>
		<pubDate>Mon, 08 Sep 2008 05:28:18 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1039#comment-42522</guid>
		<description>I don&#039;t see how this answers the original users&#039; question. He wants to have ColA where the DB will enforce a constraint on the column so that it can have unlimited null values, but all non-null values will be unique. The suggested solution is to join ColA with ColB in a composite unique key, where ColB itself is a unique column. 

However, I don&#039;t think that this will solve the problem. True, it will allow multiple nulls in ColA (since any combo of null + ColB will be unique). But it will also allow multiple non-unique, non-null values in ColA (since ColB is a unique column itself, all of the rows for ColA could equal the same value while still observing the unique constraint). Am I missing something here?</description>
		<content:encoded><![CDATA[<p>I don&#8217;t see how this answers the original users&#8217; question. He wants to have ColA where the DB will enforce a constraint on the column so that it can have unlimited null values, but all non-null values will be unique. The suggested solution is to join ColA with ColB in a composite unique key, where ColB itself is a unique column. </p>
<p>However, I don&#8217;t think that this will solve the problem. True, it will allow multiple nulls in ColA (since any combo of null + ColB will be unique). But it will also allow multiple non-unique, non-null values in ColA (since ColB is a unique column itself, all of the rows for ColA could equal the same value while still observing the unique constraint). Am I missing something here?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
