• Neeraj Dwivedi (12/17/2013)


    Try this.

    SELECT

    B.name AS TableName

    , C.name AS IndexName

    , C.fill_factor AS IndexFillFactor

    , D.rows AS RowsCount

    , A.avg_fragmentation_in_percent

    , A.page_count

    FROM sys.dm_db_index_physical_stats(null,NULL,NULL,NULL,NULL) A

    INNER JOIN sys.objects B

    ON A.object_id = B.object_id

    INNER JOIN sys.indexes C

    ON B.object_id = C.object_id AND A.index_id = C.index_id

    INNER JOIN sys.partitions D

    ON B.object_id = D.object_id AND A.index_id = D.index_id

    WHERE C.index_id > 0

    That won't work well. With null as the first parameter all databases' index physical stats are pulled, but the sys.objects and sys.indexes are local to the database this is run in, all the other indexes will be filtered out by the inner join or, if the objectID happens to match an object in the current database, return incorrect object names.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass