Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. DECLARE @TableName NVARCHAR(200) = N'humanresources.employee'
  2.  
  3. SELECT SCHEMA_NAME(o.schema_id) + '.' + OBJECT_NAME(i.object_id) AS [object]
  4. , p.partition_number AS [p#]
  5. , fg.name AS [filegroup]
  6. , p.rows
  7. , au.total_pages AS pages
  8. , CASE boundary_value_on_right
  9. WHEN 1 THEN 'less than'
  10. ELSE 'less than or equal to' END as comparison
  11. , rv.value
  12. , CONVERT (VARCHAR(6), CONVERT (INT, SUBSTRING (au.first_page, 6, 1) +
  13. SUBSTRING (au.first_page, 5, 1))) + ':' + CONVERT (VARCHAR(20),
  14. CONVERT (INT, SUBSTRING (au.first_page, 4, 1) +
  15. SUBSTRING (au.first_page, 3, 1) + SUBSTRING (au.first_page, 2, 1) +
  16. SUBSTRING (au.first_page, 1, 1))) AS first_page
  17. FROM sys.partitions p
  18. INNER JOIN sys.indexes i
  19. ON p.object_id = i.object_id
  20. AND p.index_id = i.index_id
  21. INNER JOIN sys.objects o
  22. ON p.object_id = o.object_id
  23. INNER JOIN sys.system_internals_allocation_units au
  24. ON p.partition_id = au.container_id
  25. INNER JOIN sys.partition_schemes ps
  26. ON ps.data_space_id = i.data_space_id
  27. INNER JOIN sys.partition_functions f
  28. ON f.function_id = ps.function_id
  29. INNER JOIN sys.destination_data_spaces dds
  30. ON dds.partition_scheme_id = ps.data_space_id
  31. AND dds.destination_id = p.partition_number
  32. INNER JOIN sys.filegroups fg
  33. ON dds.data_space_id = fg.data_space_id
  34. LEFT OUTER JOIN sys.partition_range_values rv
  35. ON f.function_id = rv.function_id
  36. AND p.partition_number = rv.boundary_id
  37. WHERE i.index_id < 2
  38. AND o.object_id = OBJECT_ID(@TableName);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement