Answered by:
Find fragmentation info of all indexes/tables in a database

Question
-
Hello all,
How can I find fragmentation information of all indexes/tables in a database without using dynamic management views?
Thanks.
Friday, March 11, 2011 4:18 PM
Answers
-
Check this blog post
http://www.brentozar.com/archive/2009/02/index-fragmentation-findings-part-1-the-basics/
For every expert, there is an equal and opposite expert. - Becker's Law
Naomi Nosonovsky, Sr. Programmer-Analyst
My blog- Marked as answer by Kalman Toth Tuesday, March 22, 2011 7:28 AM
Friday, March 11, 2011 4:27 PM -
Check out the following article on index fragmentation reporting:
http://www.mssqltips.com/tip.asp?tip=1708
Kalman Toth, SQL Server & BI Training; SQLUSA.com- Marked as answer by Kalman Toth Tuesday, March 22, 2011 7:28 AM
Thursday, March 17, 2011 6:34 AM
All replies
-
Hi,
Try this
select * from sys.dm_db_index_physical_stats(db_id('databasename'),null,null,null,null) where where avg_fragmentation_in_percent>15
Thanks and regards, RishabhFriday, March 11, 2011 4:19 PM -
Isn't dm_db_index_physical_stats a dynamic management view? I'm looking for a way without using them.
Thanks.
Friday, March 11, 2011 4:24 PM -
Check this blog post
http://www.brentozar.com/archive/2009/02/index-fragmentation-findings-part-1-the-basics/
For every expert, there is an equal and opposite expert. - Becker's Law
Naomi Nosonovsky, Sr. Programmer-Analyst
My blog- Marked as answer by Kalman Toth Tuesday, March 22, 2011 7:28 AM
Friday, March 11, 2011 4:27 PM -
Check out the following article on index fragmentation reporting:
http://www.mssqltips.com/tip.asp?tip=1708
Kalman Toth, SQL Server & BI Training; SQLUSA.com- Marked as answer by Kalman Toth Tuesday, March 22, 2011 7:28 AM
Thursday, March 17, 2011 6:34 AM -
HI,
this is the code for finding fragmentation status of indexes on a particular tablehope this helps...............SELECT DB_NAME(ps.[database_id]) AS [database_name], OBJECT_NAME(ps.[object_id], DB_ID()) AS [object_name], si.[name] AS [index_name], ps.[index_type_desc], ps.[avg_fragmentation_in_percent], ps.[page_count] FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, 'LIMITED') ps JOIN sys.sysindexes si ON ps.OBJECT_ID = si.id AND ps.index_id = si.indid WHERE index_type_desc <> 'HEAP' ORDER BY OBJECT_NAME(ps.[object_id], DB_ID()), index_id
Regards, Tejas Patil- Proposed as answer by jaspatil Thursday, March 17, 2011 6:46 AM
Thursday, March 17, 2011 6:46 AM -
HI,
this is the code for finding fragmentation status of indexes on a particular tableSELECT DB_NAME(ps.[database_id]) AS [database_name], OBJECT_NAME(ps.[object_id], DB_ID()) AS [object_name], si.[name] AS [index_name], ps.[index_type_desc], ps.[avg_fragmentation_in_percent], ps.[page_count] FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, 'LIMITED') ps JOIN sys.sysindexes si ON ps.OBJECT_ID = si.id AND ps.index_id = si.indid WHERE index_type_desc <> 'HEAP' ORDER BY OBJECT_NAME(ps.[object_id], DB_ID()), index_id
Regards, Tejas Patil
This query returns the list of CLUSTERED and NON CLUSTERED indexes with their page count and Freagmentation Percent.Hope this helps,
Jaspatil
Regards, Tejas PatilThursday, March 17, 2011 6:48 AM