declare @table_id int
set @table_id=object_id('SL_pe_Schema.MITask')
--执行
dbcc showcontig(@table_id)



SELECT  top 100 OBJECT_NAME(dt.object_id) 表和视图等对象,
si.name 索引名,
dt.avg_fragmentation_in_percent 外部碎片,
dt.avg_page_space_used_in_percent 内部碎片
FROM
(SELECT object_id,
index_id,
avg_fragmentation_in_percent,
avg_page_space_used_in_percent
FROM    sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, 'DETAILED')
WHERE   index_id <> 0
) AS dt --does not return information about heaps
INNER JOIN sys.indexes si
ON     si.object_id = dt.object_id
AND si.index_id  = dt.index_id
order by dt.avg_page_space_used_in_percent desc  --自己加的语句