|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Saturday, June 23, 2012 10:54 AM
Points: 8,
Visits: 23
|
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Tuesday, April 30, 2013 7:01 AM
Points: 267,
Visits: 271
|
|
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 effects INSERT statements. This should be affects. 
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.
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Wednesday, February 13, 2013 3:31 AM
Points: 55,
Visits: 39
|
|
"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.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Sunday, December 09, 2012 7:13 AM
Points: 1,
Visits: 25
|
|
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
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 9:31 AM
Points: 1,041,
Visits: 1,356
|
|
pnewhart (6/23/2011) 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.
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.
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 6:39 PM
Points: 400,
Visits: 1,432
|
|
pnewhart (6/23/2011)
First, minor grammatical point: The IGNORE_DUP_KEY option only effects INSERT statements. This should be affects. 
IMO next statement from the article
It is ignored by UPDATE, CREATE INDEX, and ALTER INDEX statements : 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'."
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 5:30 AM
Points: 861,
Visits: 1,436
|
|
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,
Best regards,
Andre Guerreiro Neto
Database Analyst http://www.softplan.com.br MCITPx1/MCTSx2
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 5:30 AM
Points: 861,
Visits: 1,436
|
|
A code showing a unique filtered index would be like this:
CREATE UNIQUE NONCLUSTERED INDEX UX_TableName_Field ON dbo.TableName(Field) WHERE Field IS NOT NULL;
Best regards,
Best regards,
Andre Guerreiro Neto
Database Analyst http://www.softplan.com.br MCITPx1/MCTSx2
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, January 23, 2013 9:53 AM
Points: 6,
Visits: 39
|
|
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 ItemTest1 where ItemNum=1
--test 2 insert into ItemTest1 select 2,'row1' union all select 2,'row2' union all select 2,'row3' order by 2
select * from ItemTest1 where ItemNum=2
--test 3 insert into ItemTest1 select 3,'row1' union all select 3,'row2' union all select 3,'row3' order by 2 desc
select * from ItemTest1 where ItemNum=3
drop table ItemTest1
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, December 28, 2012 1:42 PM
Points: 36,
Visits: 30
|
|
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
should be
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]
|
|
|
|