开发者

SQl Server indexing, same column 2 different indexes?

开发者 https://www.devze.com 2023-04-05 18:32 出处:网络
I have 2 queries I need to run against my DB.One loo开发者_Go百科ks for ManufacturerID and the other looks for ManufacturerID and SalesRepID.

I have 2 queries I need to run against my DB. One loo开发者_Go百科ks for ManufacturerID and the other looks for ManufacturerID and SalesRepID.

Should I have 1 index on ManufacturerID and 1 index on SalesRepID

OR

1 Index on ManufacturerID and 1 Index on ManufacturerID and SalesRepID?


It depends. If your table is big enough, and your data is sparse enough, it might make sense to have:

  1. Index on ManufacturerID
  2. Index on ManufacturerID, SalesRepID

On the other hand, if you have just a few different SalesRepID for each ManufacturerID, then both queries will be probably very well optimized just by using index on ManufacturerID.


Normally, you'd only need one index on both one index on ManufacturerID and SalesRepID.

A search on ManufacturerID should still use this composite index as long it is the left hand column on the index key columns.

0

精彩评论

暂无评论...
验证码 换一张
取 消