Guest User

Untitled

a guest
Apr 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. DECLARE @db_id SMALLINT;
  2. DECLARE @object_id INT;
  3.  
  4. SET @db_id = DB_ID(N'wfm');
  5. SET @object_id = OBJECT_ID(N'wfm.dbo.Lab_Employee_Time_Off');
  6.  
  7. IF @db_id IS NULL
  8. BEGIN;
  9. PRINT N'Invalid database';
  10. END;
  11. ELSE IF @object_id IS NULL
  12. BEGIN;
  13. PRINT N'Invalid object';
  14. END;
  15. ELSE
  16. BEGIN;
  17.  
  18. SELECT OBJECT_NAME(ips.OBJECT_ID) AS 'TableName'
  19. ,i.NAME AS 'IndexName'
  20. ,ips.index_id
  21. ,ips.index_type_desc
  22. ,ips.avg_fragmentation_in_percent
  23. ,ips.avg_page_space_used_in_percent
  24. ,ips.page_count
  25. FROM sys.dm_db_index_physical_stats(@db_id, @object_id, NULL, NULL, 'DETAILED') ips
  26. INNER JOIN sys.indexes i ON (ips.object_id = i.object_id)
  27. AND (ips.index_id = i.index_id)
  28. ORDER BY i.name, avg_fragmentation_in_percent DESC
  29.  
  30. END;
  31. GO
Add Comment
Please, Sign In to add comment