2009-04-07

Find fragmentation (globally)

Ok. As I am working through this certification, it is getting easier.
this is a global way to work with indexes.

select *
into #t
from sys.dm_db_index_physical_stats(null, null, null, null, null)


Then you can find the database name by selecting this:

select db_name(database_id) from #t


if you want to sift through all the gobbldygook, you can filter out non-fragmented items:

select db_name(database_id) from #t
where
fragment_count > 0 and
avg_fragmentation_in_percent > 0

... and you can build and analyze as you go.
Happy hunting!

No comments:

Post a Comment