SQL Clone
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 Eights!
SSC Eights! (812 reputation)SSC Eights! (812 reputation)SSC Eights! (812 reputation)SSC Eights! (812 reputation)SSC Eights! (812 reputation)SSC Eights! (812 reputation)SSC Eights! (812 reputation)SSC Eights! (812 reputation)

Group: General Forum Members
Points: 812 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
SSC Guru
SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)

Group: General Forum Members
Points: 61711 Visits: 13297
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?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Kingston Dhasian
Kingston Dhasian
SSCertifiable
SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)

Group: General Forum Members
Points: 5976 Visits: 5280
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
SSCarpal Tunnel
SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)

Group: General Forum Members
Points: 4390 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 Guru
SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)

Group: General Forum Members
Points: 221516 Visits: 46281
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
SSCarpal Tunnel
SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)

Group: General Forum Members
Points: 4390 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 Eights!
SSC Eights! (812 reputation)SSC Eights! (812 reputation)SSC Eights! (812 reputation)SSC Eights! (812 reputation)SSC Eights! (812 reputation)SSC Eights! (812 reputation)SSC Eights! (812 reputation)SSC Eights! (812 reputation)

Group: General Forum Members
Points: 812 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