I have a table called ‘Docs’ whose primary key is a combination of following columns: DocId,,DocStatus,DocSubId.
Now when I run following query:
select * from Docs where DocId = 200
then will it end up using the clustered index of primary key Or would it be faster to create a separate index on DocId to optimize above query.
The existing clustered index will be used, there’s no need for a separate index. On a composite index, any query on the leftmost column(s) can use the index. So, your index is also valid for a query like:
On the other hand, the composite index would not be valid for a query on only DocStatus, as the leftmost column is not used.