Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. SELECT 'DBCC DBREINDEX(''' +
  2. o.[name] + ''',''' +
  3. i.[name] + ''',' +
  4. CAST(i.fill_factor AS varchar(10)) + ')' [Fill factor],
  5. avg_fragmentation_in_percent
  6.  
  7. FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, NULL) ips
  8. INNER JOIN sys.objects o ON ips.object_id = o.object_id
  9. INNER JOIN sys.schemAS s ON o.schema_id = s.schema_id
  10. INNER JOIN sys.indexes i ON i.object_id = ips.object_id
  11. AND i.index_id = ips.index_id
  12. WHERE i.[name] IS NOT NULL AND avg_fragmentation_in_percent >0
  13.  
  14. order by avg_fragmentation_in_percent desc,i.[name]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement