Reputation: 2213
I have enabled sql profiler and identified several queries that are taking a long time to execute.
For example:
Select A from table_A where B = 2
My question is, based on above query, do I create indexes on column A or B? or A and B?
Upvotes: 1
Views: 170
Reputation: 13506
Create seperate indexes on B and A. Creating index on A is to avoid KEY LOOKUP.
Upvotes: 0
Reputation: 171178
Index on B
including column A
. The where can use a seek on B
while still returning A
.
Upvotes: 0
Reputation: 1
I would create an index on column B because that is what sql server is doing the comparison on. Afterwards I would run the profiler again to see if adding the index negatively impacts other queries.
Upvotes: 0
Reputation: 8895
Your index should be on B since that's what is in your condition. You might benefit from just trying out all the ways and looking at the resulting execution plans.
Upvotes: 1