|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Yesterday @ 7:06 AM
Points: 730,
Visits: 1,706
|
|
| Whats the significance of Nonclustered Versus Unique NonClustered indexes if at all possible to have a unique key(one of the column is identity)?
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 2:12 AM
Points: 1,322,
Visits: 4,400
|
|
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?
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Yesterday @ 7:06 AM
Points: 730,
Visits: 1,706
|
|
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 }
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 3:55 AM
Points: 13,381,
Visits: 25,165
|
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Yesterday @ 7:06 AM
Points: 730,
Visits: 1,706
|
|
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 key
If 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 key
If 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....
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Wednesday, April 10, 2013 10:10 PM
Points: 307,
Visits: 1,390
|
|
| 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).
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 1:53 PM
Points: 2,984,
Visits: 4,403
|
|
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) Berzukov
Author 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.
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 3:30 AM
Points: 37,725,
Visits: 29,982
|
|
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 Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 3:35 AM
Points: 5,678,
Visits: 6,125
|
|
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 Farrell
Never 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 Netiquette For index/tuning help, follow these directions. |Tally Tables Twitter: @AnyWayDBA
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 3:30 AM
Points: 37,725,
Visits: 29,982
|
|
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 Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|