Hello all,
I had some SQL queries which are using department ID for join , filter , Group By and Select
so , i am having index on department ID of my table File Master
scheme ..
CREATE TABLE [dbo].[FILE_MASTER](
[FILE_ID] [INT] IDENTITY(1,1) NOT NULL,
[DEPARTMENT_ID] [INT] NULL,
[CLIENT_ID] [INT] NULL
,[LEAD_DETAIL_ID] [INT] NULL
,[FILE_NO] [NVARCHAR](50) NULL,
[INWARD_DATE] [DATETIME] NULL,
[LOAN_SANCTION_DATE] [DATETIME] NULL,
CONSTRAINT [PK_FILE_MASTER] PRIMARY KEY CLUSTERED
(
[FILE_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [Indx_FM_department_ID] ON [dbo].[FILE_MASTER]
(
[DEPARTMENT_ID] ASC
)
INCLUDE ( [FILE_ID],
[FILE_NO],
[INWARD_DATE],
[CLIENT_ID],
[LOAN_SANCTION_DATE],
) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
GO
The above index only working when there is condition or group by on department ID .
and i when i am querying ..
SELECT DISTINCT CL.CLIENT_ID,CL.LOAN_SANCTION_DATE,MIN(CL.INWARD_DATE)AS Inward
FROM dbo.FILE_MASTER AS CL
GROUP BY CL.CLIENT_ID,CL.LOAN_SANCTION_DATE
and the plan is showing Index scan on index Indx_FM_department_ID ..
can any one tell me why it is not using Index seek , i guess i have both group by Columns in cover index included columns
what is the use of cover index then ??
because if i am giving where condition before group by for specific Client ID , Loan Sanction Date
it is telling to create separate index on client ID , Loan Sanction Date as per Execution Plan missing index detail ..
please advice ..