Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 Nonclustered Versus Unique NonClustered Rate Topic Display Mode Topic Options
Author
 Message
 Posted Wednesday, February 16, 2011 11:32 PM
 Right there with Babe Group: General Forum Members Last Login: Sunday, November 6, 2016 10:25 PM Points: 731, Visits: 2,150
 Whats the significance of Nonclustered Versus Unique NonClustered indexes if at all possible to have a unique key(one of the column is identity)?
Post #1065445
 Posted Thursday, February 17, 2011 1:40 AM
 Ten Centuries Group: General Forum Members Last Login: Yesterday @ 2:07 AM Points: 1,408, Visits: 6,190
 The simple answer is that SQL Server will make sure that only one row exists for a given value if you declare the index as UNIQUE, otherwise you can have as many rows as you want with the same value.Is there more to your question?
Post #1065487
 Posted Thursday, February 17, 2011 3:22 AM
 Right there with Babe Group: General Forum Members Last Login: Sunday, November 6, 2016 10:25 PM Points: 731, Visits: 2,150
 Okei, thank for your post. I found something very interesting as below:I just changed the post little bit to have a better reading....(oops fed up with formating the same...)In our table,If (Unique Clustered) If (Non - Clustered - unique) { Btree- Non-clustered Key Leaf-Non Clustered Key + Clustered Key } else if (Non - Clustered = NonUnique ) { Btree- Non-Clustered Key + Cluster Key Leaf- Non-Clustered Key + Cluster Key }if (Non-Unique Clustered) If(Non - Clustered = Unique) { Btree- Non - Clusetered Key Leaf - Non - Clusetered Key + Cluster Key + UQI } else if (Non - Clustered= non unique) { Btree- Non - Clusetered Key + Cluster Key + UQI Leaf- Non - Clusetered Key + Cluster Key + UQI }
Post #1065534
 Posted Thursday, February 17, 2011 4:58 AM
 SSCoach Group: General Forum Members Last Login: 2 days ago @ 12:29 PM Points: 17,173, Visits: 32,140
 Could you explain what that means please? I don't understand what you posted. ----------------------------------------------------"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore RooseveltThe Scary DBAAuthor of: SQL Server Query Performance Tuning and SQL Server Execution PlansProduct Evangelist for Red Gate Software
Post #1065564
 Posted Thursday, February 17, 2011 9:52 AM
 Right there with Babe Group: General Forum Members Last Login: Sunday, November 6, 2016 10:25 PM Points: 731, Visits: 2,150
 I was just trying to convey like whats the significance of unique key while creating indexes. To me, while I was checking with DBCC IND and PAGE, I could see the above situation. The non-clustered index key structure would be as follows:If I have a unique clustered index index and non-unique non-clusterd index indexthen my root level will have non-clustered key + clustered key. At leaf level, non-clustered key + clustered keyIf I have a unique clustered index index and unique non-clusterd index indexthen my root level will have non-clustered key . At leaf level, non-clustered key + clustered keyIf I have a non-unique clustered index index and non-unique non-clusterd index indexthen my root level will have non-clustered key + clustered key + Uniquifier. At leaf level, non-clustered key + clustered key + Uniquifier.If I have a non-unique clustered index index and unique non-clusterd index indexthen my root level will have non-clustered key . At leaf level, non-clustered key + clustered key +Uniquifier.Correct me if am wrong....
Post #1065806
 Posted Thursday, February 17, 2011 10:17 AM
 SSC-Addicted Group: General Forum Members Last Login: Thursday, June 23, 2016 11:15 AM Points: 413, Visits: 1,444
 What you saw is CORRECT. And I am sure you know the structure of non-clustered index: the leaf level must have a clustered index key attached (if the clustered index is not unique, it must have the RID attached for the uniqueness).
Post #1065831
 Posted Thursday, February 17, 2011 10:18 AM
 Hall of Fame Group: General Forum Members Last Login: Tuesday, January 28, 2014 8:15 AM Points: 3,065, Visits: 4,639
 sqlchanakya (2/17/2011)I was just trying to convey like whats the significance of unique key while creating indexes...mmhhh... to enforce uniqueness perhaps? _____________________________________Pablo (Paul) BerzukovAuthor of Understanding Database Administration available at Amazon and other bookstores.Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Post #1065832
 Posted Thursday, February 17, 2011 10:44 AM
 SSC-Forever Group: General Forum Members Last Login: Saturday, December 3, 2016 5:18 AM Points: 45,619, Visits: 44,147
 Wildcat (2/17/2011) (if the clustered index is not unique, it must have the RID attached for the uniqueness).Nope. The only time the RID is used in a nonclustered index is when the base table is a heap (no clustered index) Gail ShawMicrosoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)SQL In The Wild: Discussions on DB performance with occasional diversions into recoverabilityWe walk in the dark places no others will enterWe stand on the bridge and no one may pass
Post #1065854
 Posted Thursday, February 17, 2011 11:04 AM
 SSCertifiable Group: General Forum Members Last Login: Wednesday, September 23, 2015 3:34 PM Points: 5,467, Visits: 7,660
 GilaMonster (2/17/2011)Wildcat (2/17/2011) (if the clustered index is not unique, it must have the RID attached for the uniqueness).Nope. The only time the RID is used in a nonclustered index is when the base table is a heap (no clustered index)That little off the cuff statement has me doing some research...Isn't the RID and the "uniquifier" pretty much equivalent from an overhead standpoint, being a 4 byte identifier?That and I've seen some conflicting information about said "uniquifier" being only applied to duplicated index rows. Every time I think I've got this nailed down it slips sideways a little bit on me. - Craig FarrellNever stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake. For better assistance in answering your questions | Forum NetiquetteFor index/tuning help, follow these directions. |Tally TablesTwitter: @AnyWayDBA
Post #1065870
 Posted Thursday, February 17, 2011 11:25 AM
 SSC-Forever Group: General Forum Members Last Login: Saturday, December 3, 2016 5:18 AM Points: 45,619, Visits: 44,147
 Craig Farrell (2/17/2011)Isn't the RID and the "uniquifier" pretty much equivalent from an overhead standpoint, being a 4 byte identifier?No. To start with, the RID's not 4 bytes.The RID is the row identifier. An 8 byte combination of file, page and slot. Every row has one, it is unique always. The uniquifier is a 4-byte sequential value that only appears on the rows that have duplicate clustered index key values (the first row SQL encounters won't have a uniquifier, any rows subsequent with the same clustering key will gain one, sequential value, starting at (I believe) 1. It's ony unique in combination with the clustering key, not by itself. Gail ShawMicrosoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)SQL In The Wild: Discussions on DB performance with occasional diversions into recoverabilityWe walk in the dark places no others will enterWe stand on the bridge and no one may pass
Post #1065876

 Permissions