August 20, 2014 at 11:16 am
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!!
August 20, 2014 at 11:24 am
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
Consultant - Straight Path Solutions
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
August 20, 2014 at 11:30 am
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?
August 20, 2014 at 11:47 am
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[/url] has links to all of them. She explains things much better than I could.
Jack Corbett
Consultant - Straight Path Solutions
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
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply