Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT 'DBCC DBREINDEX(''' +
- o.[name] + ''',''' +
- i.[name] + ''',' +
- CAST(i.fill_factor AS varchar(10)) + ')' [Fill factor],
- avg_fragmentation_in_percent
- FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, NULL) ips
- INNER JOIN sys.objects o ON ips.object_id = o.object_id
- INNER JOIN sys.schemAS s ON o.schema_id = s.schema_id
- INNER JOIN sys.indexes i ON i.object_id = ips.object_id
- AND i.index_id = ips.index_id
- WHERE i.[name] IS NOT NULL AND avg_fragmentation_in_percent >0
- order by avg_fragmentation_in_percent desc,i.[name]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement