SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Indexing Question


Indexing Question

Author
Message
GBeezy
GBeezy
Old Hand
Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)

Group: General Forum Members
Points: 311 Visits: 711
My MailingAddress table currently has a Non Clustered index on the ProcessID column. Using a Missing Indexes query I have, it is recommending that I add the following:

CREATE INDEX [IX_MailingAddress_ProcessID_PrintFlag] ON [DB1].[dbo].[MailingAddress] ([ProcessID], [PrintFlag]) INCLUDE ([RunNum])

I am under the impression that I should either delete the existing index on ProcessID and add this one or should I add the suggested index while keeping the index only on ProcessID as well?

Thanks for the help!!
Jack Corbett
  Jack Corbett
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18362 Visits: 14893
Neither is another option.

When working on indexing you need to consider the all the ways a table will be queried to come up with the best indexes. In your one example, the recommended index is probably better than the single column index because it is highly unlikely that you will only be returning ProcessID in your query, so you'll require a lookup (key or rid) to retrieve the rest of the columns used in the query. The issue with the recommended index is that there might be other queries that would use the same key values but return columns other than RunNum, so an index without an INCLUDE might be the best way for the table or an index with and INCLUDE that has more than the just the RowNum column.



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
GBeezy
GBeezy
Old Hand
Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)

Group: General Forum Members
Points: 311 Visits: 711
Thanks Jack for the response.

I have another question, I just started at this job and I am seeing tables that do not have a PK or a Clustered Index on them. I have a feeling that I should be finding a good column to create a clustered index on and get it done. I am wondering what if any negative side effects this could have??? Can you shed some light on this for me?
Jack Corbett
  Jack Corbett
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18362 Visits: 14893
GBeezy (8/20/2014)
Thanks Jack for the response.

I have another question, I just started at this job and I am seeing tables that do not have a PK or a Clustered Index on them. I have a feeling that I should be finding a good column to create a clustered index on and get it done. I am wondering what if any negative side effects this could have??? Can you shed some light on this for me?


First, don't confuse Primary Keys and Clustered Indexes as they are different things and serve different purposes. A Primary Key is something that defines a unique entity, by default, SQL Server does create a clustered index when creating a Primary Key, but you don't have to do that. A Clustered Index defines the logical order the data in the table is stored in. A primary key can be a business key or a surrogate key (should always be backed up with a business key) and if it is a business key it often is not the best candidate for clustering.

SQL Server does tend to work better with tables that have a clustered index than with heaps, with the caveat that you have chosen the right column(s) for the clustering key. I'd start by reading all the posts by Kimberly Tripp on clustered indexes. This one has links to all of them. She explains things much better than I could.



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
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