View fragmentation percentage of the indexes on a table in SQL Server

Hi Geeks,

Today I am sharing SQL query often required during performance tuning/Optimization phase of the project.The query makes use of system DMV’s provided by SQL server.Open new query window in SQL Server and fire the below query against the respective database.Just pass in the name of the table and the database for which you want to view the fragmentation.

, ROUND(s.avg_fragmentation_in_percent,2) AS [Fragmentation %]
FROM sys.dm_db_index_physical_stats(DB_ID(‘parisdev’),
OBJECT_ID(‘currency’), NULL, NULL, NULL) s
INNER JOIN sys.indexes i ON s.[object_id] = i.[object_id]
AND s.index_id = i.index_id




I would like to have feedback from my blog readers.

Please post your feedback, question, or comments about this article.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s