Sql-server – Does composite cluster index affect performance of seek/scan non-cluster index which is part of the composite

database-designindexsql serversql-server-2008

I have bank transaction table with columns

Division
Brcode
TrDate
ProjectCode
Accountnumber
EffectiveDate
DrCr
Amount
EndBalance

In the other table the Brcode itself is unique and is assigned under only 1 division.

I am planing to set Division,Brcode,TrDate as cluster index(composite) and set each of them as non-cluster index individually.

What I curious is

  1. since Brcode is unique for all division so clustering Division,Brcode,TrDate is implicitly clustering Brcode,does Brcode index get benefit from this? Does it need to search all division?

  2. If I search by TrDate it won't get benefit from cluster index,is that right? this column shouldn't include in composite?

  3. If I search by TrDate will cause full table scan or index scan?

ps.this table have 7 millions record so even minor factor will cause a huge different 🙁

Best Answer

First off, don't mix "primary key" and "clustered index". One is "how to identify a row", the other is "on-disk structure"

Then, you don't need an index on Division by itself because it is the left hand column of the clustered index. However, it won't be covering (see links below)

And for each point in turn:

  1. this table doesn't know that "Brcode is unique for all division". If it is, then brCode should be first and unique and the clustered index by itself
  2. a search on TrDate won't benefit from the clustered index
  3. it depends on selectivity, statistics, how many columns are required. It may seek with a key lookup or it may scan the clustered index (= a table scan) or scan/seek the index on TrDate

Finally, I'd suggest some background reading: