﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by David Durant  / Stairway to SQL Server Indexes: Step 8, Unique Indexes / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 05:09:30 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Stairway to SQL Server Indexes: Step 8, Unique Indexes</title><link>http://www.sqlservercentral.com/Forums/Topic1082875-2904-1.aspx</link><description>[code="sql"]SELECT [Name]     , COUNT(*) AS 'RowCount'     , SUM(LineTotal) AS 'TotalValue'  FROM Production.Product P  JOIN Sales.SalesOrderDetail D ON D.ProductID = P.ProductID   GROUP BY ProductID [/code]should be[code="sql"]SELECT [Name]     , COUNT(*) AS 'RowCount'     , SUM(LineTotal) AS 'TotalValue'  FROM Production.Product P  JOIN Sales.SalesOrderDetail D ON D.ProductID = P.ProductID   GROUP BY [Name][/code]</description><pubDate>Wed, 11 Apr 2012 12:55:14 GMT</pubDate><dc:creator>noviceinsql</dc:creator></item><item><title>RE: Stairway to SQL Server Indexes: Step 8, Unique Indexes</title><link>http://www.sqlservercentral.com/Forums/Topic1082875-2904-1.aspx</link><description>Quick question regarding ignore_dup_key option:If the attempted insert includes multiple "duplicates", how do you control which one succeeds.   From trial and error, it looks like if my set of duplicates is ordered, the first row will be successful and the subsequent rows will fail.  (See test 2 and test 3 below.)  But it would sure be nice if someone could confirm that this is the defined behavior.   Anyone?    Thanks.create table ItemTest1( ItemNum int ,Value varchar(10))go create unique index  pk_ItemTest1 on ItemTest1(ItemNum) with (IGNORE_DUP_KEY = ON)go   --test 1  insert into ItemTest1 select 1,'row1'   union all select 1,'row2'   union all select 1,'row3'    select * from ItemTest1where ItemNum=1--test 2 insert into ItemTest1 select 2,'row1'   union all select 2,'row2'   union all select 2,'row3' order by 2select * from ItemTest1where ItemNum=2--test 3insert into ItemTest1 select 3,'row1'   union all select 3,'row2'   union all select 3,'row3' order by 2 descselect * from ItemTest1where ItemNum=3drop table ItemTest1</description><pubDate>Fri, 06 Jan 2012 15:19:58 GMT</pubDate><dc:creator>mmilodragovich</dc:creator></item><item><title>RE: Stairway to SQL Server Indexes: Step 8, Unique Indexes</title><link>http://www.sqlservercentral.com/Forums/Topic1082875-2904-1.aspx</link><description>A code showing a unique filtered index would be like this:[code]CREATE UNIQUE NONCLUSTERED INDEX UX_TableName_Field ON dbo.TableName(Field) WHERE Field IS NOT NULL;[/code]Best regards,</description><pubDate>Wed, 14 Sep 2011 11:06:24 GMT</pubDate><dc:creator>codebyo</dc:creator></item><item><title>RE: Stairway to SQL Server Indexes: Step 8, Unique Indexes</title><link>http://www.sqlservercentral.com/Forums/Topic1082875-2904-1.aspx</link><description>I have seen that technique of combining unique indexes with filtered indexes before and it's really great to be able to do that. Thanks for bringing it up.I really like how you explain many questions at once in your article. That unique constraint VS unique indexes part was one of them.Best regards,</description><pubDate>Wed, 14 Sep 2011 10:27:31 GMT</pubDate><dc:creator>codebyo</dc:creator></item><item><title>RE: Stairway to SQL Server Indexes: Step 8, Unique Indexes</title><link>http://www.sqlservercentral.com/Forums/Topic1082875-2904-1.aspx</link><description>[quote][b]pnewhart (6/23/2011)[/b][hr]First, minor grammatical point:  The IGNORE_DUP_KEY option only [i]effects[/i] INSERT statements.  This should be [i]affects[/i].  :-)[/quote]IMO next statement from the article [quote]  It is ignored by UPDATE, CREATE INDEX, and ALTER INDEX statements :[/quote] is not correct as IGNORE_DUP_KEY does affect UPDATE statements-try it and you will get error "Cannot insert duplicate key row in object 'dbo.mytbl' with unique index 'nc_index1'."</description><pubDate>Wed, 14 Sep 2011 08:15:47 GMT</pubDate><dc:creator>Yuri55</dc:creator></item><item><title>RE: Stairway to SQL Server Indexes: Step 8, Unique Indexes</title><link>http://www.sqlservercentral.com/Forums/Topic1082875-2904-1.aspx</link><description>[quote][b]pnewhart (6/23/2011)[/b][hr]Second, how are you demonstrating to allow duplicate NULL values using a filter?  Unless some screen prints are missing, I don't see how that's being illustrated.  And, unless I'm misunderstanding the functionality of the IGNORE DUP_KEY=ON, this would still only allow one NULL value since it's defined as allowing the inserts to only fail those having duplicate values.  [/quote]Seconded. If you look closely at the article section on allowing duplicate NULLs, you see a reference to an index AK_UPCode, which is not created in the preceding DDL statements. So something is clearly missing there. Compounding this is the fact that the header for choosing the correct IGNORE DUP_KEY option is not formatted as a header, so the two sections run into each other.</description><pubDate>Wed, 14 Sep 2011 07:44:23 GMT</pubDate><dc:creator>sknox</dc:creator></item><item><title>RE: Stairway to SQL Server Indexes: Step 8, Unique Indexes</title><link>http://www.sqlservercentral.com/Forums/Topic1082875-2904-1.aspx</link><description>First articles were very intelligible.Now it's hard to understand all nuances without good examples. Step 8 does not provide all sqls.The same problem peculiar to article #7.Seems that author just tired and decided to save time :(</description><pubDate>Thu, 28 Jul 2011 04:48:16 GMT</pubDate><dc:creator>vas1l</dc:creator></item><item><title>RE: Stairway to SQL Server Indexes: Step 8, Unique Indexes</title><link>http://www.sqlservercentral.com/Forums/Topic1082875-2904-1.aspx</link><description>"The best way to provide this functionality is to combine a unique index with a filtered index."It looks like you forgot (deliberately?) to include the code to create this index within the body of the article.</description><pubDate>Tue, 26 Jul 2011 04:49:00 GMT</pubDate><dc:creator>simonharpham</dc:creator></item><item><title>RE: Stairway to SQL Server Indexes: Step 8, Unique Indexes</title><link>http://www.sqlservercentral.com/Forums/Topic1082875-2904-1.aspx</link><description>Great series so far.  However, I think things are starting to blur in my mind.First, minor grammatical point:  The IGNORE_DUP_KEY option only [i]effects[/i] INSERT statements.  This should be [i]affects[/i].  :-)Second, how are you demonstrating to allow duplicate NULL values using a filter?  Unless some screen prints are missing, I don't see how that's being illustrated.  And, unless I'm misunderstanding the functionality of the IGNORE DUP_KEY=ON, this would still only allow one NULL value since it's defined as allowing the inserts to only fail those having duplicate values.  Again, maybe I'm just missing something.  Unfortunately, I'm just a lowly contract developer looking to fill some downtime, so I don't have the ability to add the AW db; therefore I can't try to duplicate the demos.Thanks.</description><pubDate>Thu, 23 Jun 2011 09:03:30 GMT</pubDate><dc:creator>pnewhart</dc:creator></item><item><title>Stairway to SQL Server Indexes: Step 8, Unique Indexes</title><link>http://www.sqlservercentral.com/Forums/Topic1082875-2904-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/articles/Stairway+Series/72440/"&gt;Stairway to SQL Server Indexes: Step 8, Unique Indexes&lt;/A&gt;[/B]</description><pubDate>Wed, 23 Mar 2011 11:32:18 GMT</pubDate><dc:creator>David Durant</dc:creator></item></channel></rss>