Sql Server

SQL | Filtered Indexes

SQL | Filtered Indexes

SQL | Filtered Indexes

A SQL Server filtered index is a non-clustered index that allows us to apply specific conditions to cover a subset of rows in the table.

This can save on space, improve on query performance and reduce maintenance overhead as the index is much smaller.
For Example, we have a student table and in our web application we only requests the active students data. In this case, create an index for the only active student rows is very reasonable than creating an index for whole rows of the table.



Create Filtered Index
A filtered index is created simply by adding a WHERE clause to any non-clustered index creation statement.

CREATE NONCLUSTERED INDEX IX_Student_Roll_No_INC_IsActive ON Student
(Roll_No ASC) WHERE IsActive=1;



Confirm Index Usage
The following query should use our newly created index.

SELECT Name FROM Student
WHERE IsActive=1
ORDER BY Roll_No ASC;




Related Post

About Us

Community of IT Professionals

A Complete IT knowledgebase for any kind of Software Language, Development, Programming, Coding, Designing, Networking, Hardware and Digital Marketing.

Instagram