We have an existing table structure as below
Table Name: Provider #
Columns:
Provid
EntityId
SpecialityCode
ProvType
FedId
FullName
Status
In this table, ProvId is the primary key. So we have a clustered index on ProvId.
Apart from this, we have two composite nonclustered indexes as below
CREATE NONCLUSTERED INDEX [Provider0] 
ON [dbo].[provider] ([fedid] ASC, [provid] ASC, [entityid] ASC, [fullname] ASC, [status] ASC)
CREATE NONCLUSTERED INDEX [XIE3Provider] 
ON [dbo].[provider] ([fedid] ASC, [entityid] ASC, [provtype] ASC, [fullname] ASC, [provid] ASC, )
Query 1:
SELECT provid 
FROM provider 
WHERE FedId = '123'
For query 1, SQL Server uses XIE3Provider index for seek operation.
Query 2:
SELECT provid, status 
FROM provider 
WHERE FedId = '123'
For query 2, SQL Server uses the Provider0 index for seek operation.
Could you please provide more details as to how SQL Server switches the index selection for this case?
 
     
     
    