I have a table with more than 40k rows and a primary key consisting of 2 columns on this table.
Could a seperate nonclustered (NOT unique!) index on ONE of these primary key columns speed up queries on THIS column (without using the other PK columns)? Or would SQL Server use the primary key in an equally efficient manner for accessing only one column of the primary key?
I know a primary key is a unique index but that has nothing to do with the question, I’m just concerned about the primary key spanning multiple columns as opposed to one when accessing data just from one of the PK columns..
Supposing the PK is on: Field1, Field2 (in that order)
So in the final case, you may consider a separate index on Field2. Note there is a bit more to it if e.g. you are returning other fields in the table other than the PK fields. In this case, if your PK is CLUSTERED (by default, PKs are) then the data is already in the index. But in a NONCLUSTERED index (e.g. if you created one on Field2), it would have to then go off and perform a lookup to get the other fields being returned for the query. So then you can get into the realms of deciding whether to INCLUDE columns in the NONCLUSTERED index or not.
Recommend doing a bit of reading up on this, it’s worth getting up to speed.