Answered by:
whats the difference between these Indexes?

Question
-
1- CREATE UNIQUE NONCLUSTERED INDEX idx_LatestPosts_1 ON dbo.LatestPosts(
Country ASC
,PostCateGory ASC
,PostID DESC
);2- CREATE NONCLUSTERED INDEX idx_LatestPosts_1 ON dbo.LatestPosts(Country) InClude(PostCateGory)
as i understand we should Use Include statementright only if both Counry and PostcateGory are Unique its right??
there is any more differences?
Tuesday, February 14, 2012 1:33 PM
Answers
-
Hi Greaso,
Unique indexes and included columns are 2 totally seperate concepts.
A unique index is a normal nonclustered index, wich maintains a unique constraint on the column or combination of columns that form the index key.
When you use included columns, instead of the key being stored at every level of the B-Tree structure, the included columns are only included in the index at the leaf level. This allows you to build covering index (indexes that cover every column in a query) without having hugh, inefficient indexes. It also allows you to get arounf the 900 byte/16 column limitation of index keys.
Both clustered and non-clustered indexes can be unique or non-unique. You can only include columns in a non-clustered index, but technically, in a clustered index, all columns are included anyway.
Hope this helps.
Pete
Peter Carter http://sqlserverdownanddirty.blogspot.com/
Tuesday, February 14, 2012 1:41 PM -
Aslo please read this link
http://technet.microsoft.com/en-us/library/ms189607.aspx
VT
Please mark answered if I've answered your question and vote for it as helpful to help other user's find a solution quicker
- Marked as answer by greaso Tuesday, February 14, 2012 3:09 PM
Tuesday, February 14, 2012 1:47 PM
All replies
-
Hi Greaso,
Unique indexes and included columns are 2 totally seperate concepts.
A unique index is a normal nonclustered index, wich maintains a unique constraint on the column or combination of columns that form the index key.
When you use included columns, instead of the key being stored at every level of the B-Tree structure, the included columns are only included in the index at the leaf level. This allows you to build covering index (indexes that cover every column in a query) without having hugh, inefficient indexes. It also allows you to get arounf the 900 byte/16 column limitation of index keys.
Both clustered and non-clustered indexes can be unique or non-unique. You can only include columns in a non-clustered index, but technically, in a clustered index, all columns are included anyway.
Hope this helps.
Pete
Peter Carter http://sqlserverdownanddirty.blogspot.com/
Tuesday, February 14, 2012 1:41 PM -
Aslo please read this link
http://technet.microsoft.com/en-us/library/ms189607.aspx
VT
Please mark answered if I've answered your question and vote for it as helpful to help other user's find a solution quicker
- Marked as answer by greaso Tuesday, February 14, 2012 3:09 PM
Tuesday, February 14, 2012 1:47 PM