Finding Fragmentation Rates of Indexes in SQL Server

Hello to everyone,

In this article, I will try to give information about finding Fragmentation rates of Indexes in SQL Server.

In SQL Server, in some cases, you may want to find the Fragmentation rates of Indexes.

You can easily do this using the code below.

SELECT ps.object_id,
       i.name AS IndexName,
       OBJECT_SCHEMA_NAME(ps.object_id) AS ObjectSchemaName,
       OBJECT_NAME(ps.object_id) AS ObjectName,
       ps.avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, 'LIMITED') ps
    INNER JOIN sys.indexes i
        ON i.object_id = ps.object_id
           AND i.index_id = ps.index_id
WHERE avg_fragmentation_in_percent > 5
      AND ps.index_id > 0
ORDER BY avg_fragmentation_in_percent DESC;

When you run the above code, you will see a result similar to the one below.

Finding Fragmentation Rates of Indexes in SQL Server

As can be seen, the Fragmentation rates of the Indexes have been found.

Good luck to everyone in business and life.

92 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!