Fragmentation in SQL 2005

  • I am trying to use sql 2005 dynamic views to caputre fragmentation but it is taking forever but when I use DBCC SHOWCONTIG(TableName), it's very fast.

    DECLARE @DB_ID INT

    SELECT @DB_ID = DB_ID()

    SELECT TableName = object_name(object_id), database_id, index_id, index_type_desc,

    avg_fragmentation_in_percent, fragment_count, page_count

    FROM sys.dm_db_index_physical_stats (@DB_ID, null, NULL, NULL , 'LIMITED')

    WHERE object_name(object_id) is not null

    and avg_fragmentation_in_percent > 30 AND PAGE_COUNT > 1000

    and object_name(object_id) ='TableName'

  • Hi Balbir,

    Check this link:

    http://blogs.techrepublic.com.com/datacenter/?p=251

    Thank You,

    Best Regards,

    SQL Buddy

  • Wow. That is pretty faster. I will use the one in the article.

    Thanks man

  • Hi Balbir,

    You're more than welcome.

    Good Luck!

    Yours

    SQLBuddy.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply