Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Nonclustered Versus Unique NonClustered


Nonclustered Versus Unique NonClustered

Author
Message
Latheesh NK
Latheesh NK
Right there with Babe
Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)

Group: General Forum Members
Points: 739 Visits: 2156
Whats the significance of Nonclustered Versus Unique NonClustered indexes if at all possible to have a unique key(one of the column is identity)?
Ian Scarlett
Ian Scarlett
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1420 Visits: 6255
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?



Latheesh NK
Latheesh NK
Right there with Babe
Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)

Group: General Forum Members
Points: 739 Visits: 2156
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
}
Grant Fritchey
Grant Fritchey
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17553 Visits: 32252
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 Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Latheesh NK
Latheesh NK
Right there with Babe
Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)Right there with Babe (739 reputation)

Group: General Forum Members
Points: 739 Visits: 2156
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....
Wildcat
Wildcat
SSC-Addicted
SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)

Group: General Forum Members
Points: 423 Visits: 1444
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).
PaulB-TheOneAndOnly
PaulB-TheOneAndOnly
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3093 Visits: 4639
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? :-D

_____________________________________
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.
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47173 Visits: 44348
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, MVP, M.Sc (Comp Sci)
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


Evil Kraig F
Evil Kraig F
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5695 Visits: 7660
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)


Blink

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
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47173 Visits: 44348
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, MVP, M.Sc (Comp Sci)
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


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search