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


Columns to be included in Index


Columns to be included in Index

Author
Message
Krishna1
Krishna1
SSC Veteran
SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)

Group: General Forum Members
Points: 218 Visits: 556
Dear All

I have one table with millions of rows, with columns as Id, stringcol1,stringcol2,Bigintcol3,numericcol4
Primary key is Id.
Index created on stringcol1

When I query this table ,

select sum(numericcol4), Bigintcol3
from abc
where stringcol1 = @stringcol1
and stringcol2 = @stringcol2
and Bigintcol3 in not null
group by Bigintcol3

It shows me to create index with columns as stringcol1,stringcol3,Bigintcol3 include numericcol4

If I exclude any column from the recommended index and check Estimated Plan it shows as index scan on Primary key
Does it means that in sql 2008 R2 we need to create indexes to include all the column in the “where clause” and also add filed of the select statement in the include column list ?


Regards
Krishna1
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16564 Visits: 13210
Krishna1 (3/27/2013)
...
Does it means that in sql 2008 R2 we need to create indexes to include all the column in the “where clause” and also add filed of the select statement in the include column list ?


Not only in SQL Server 2008R2, but also in other editions ;-)
The suggested index is a covering index. It is designed specifically for your query and takes into account every column in the WHERE clause (the filtering columns) and it includes the column from the SELECT clause, so a lookup doesn't need to be done to retrieve numericcolumn4 from the pages.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
Kingston Dhasian
Kingston Dhasian
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3007 Visits: 5016
INCLUDED columns were introduced in SQL Server 2005
They can improve performance by avoiding key look ups as the necessary columns are included along with the key columns in the indexes

You can check the below mentioned link for more information on INCLUDED columns
http://msdn.microsoft.com/en-us/library/ms190806%28v=sql.90%29.aspx

Edit: Added the link


Kingston Dhasian

How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
AndrewSQLDBA
AndrewSQLDBA
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1008 Visits: 3427
I mean this in a nice way.

That is a horrible naming convention that you have. Please change that mess. How in the world do you have any idea what is actually in any column?

Andrew SQLDBA
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: 47447 Visits: 44405
It's probably just a quick example, or an obfuscated table. See the column names that I use in my writing for useless.

Usually like
SELECT SomeInt, SomeString, SomeDate from SomeTable


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


AndrewSQLDBA
AndrewSQLDBA
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1008 Visits: 3427
Hey Gila
Yes, I do the same, but I indicate such and surround the fake table name with tags to give a visual indicator.

ie....

<TableName>.<ColumnName>

Andrew SQLDBA
Krishna1
Krishna1
SSC Veteran
SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)

Group: General Forum Members
Points: 218 Visits: 556
Tbale is having many columns which are not referd in the query. Hence i had used these column names which specify what datatype they have in the table.
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