通过下面的 SQL 查询数据库的索引碎片
SELECT OBJECT_NAME(ind.OBJECT_ID) AS TableName,
ind.name AS IndexName, indexstats.index_type_desc AS IndexType,
indexstats.avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, NULL) indexstats
INNER JOIN sys.indexes ind
ON ind.object_id = indexstats.object_id AND ind.index_id = indexstats.index_id
WHERE indexstats.avg_fragmentation_in_percent > 80
ORDER BY indexstats.avg_fragmentation_in_percent DESC
发现一个 HEAP 类型的索引碎片,请问如何整理这个索引碎片?
是因为对应的表缺少聚集索引,加上聚集索引即可解决