select t.name as TableName, i.name as IndexName,
DB_NAME(s.database_id) as DatabaseName
from sys.indexes i
inner join sys.dm_db_index_usage_stats s on s.object_id = i.object_id
and s.index_id = i.index_id
inner join sys.tables t on i.object_id = t.object_id
where ( (user_seeks = 0 and user_scans = 0 and user_lookups = 0)
or
s.object_id is null
)
and s.database_id = DB_ID(' DbName')
2) This query builds a list of indexes that could benefit from ALTER INDEX REBUILD or ALTER INDEX REGORGANIZE.
select t.name as TableName
, i.name as IndexName
from sys.indexes i
inner join sys.dm_db_index_usage_stats s on s.object_id = i.object_id and s.index_id = i.index_id
inner join sys.tables t on i.object_id = t.object_id
inner join #frag_indexes f on i.object_id = f.object_id and i.index_id = f.index_id
order by s.user_scans desc, f.priority asc
No comments:
Post a Comment