SQL Server : Query For A Quick Overview Of Your Partitions

— =============================================

— This is a basic query intended to provide

— a quick look at partition info.  

— =============================================

 

SELECT b.name as ‘table_name’, a.partition_number,

a.[rows] as ‘row_count’, a.partition_id,

a.object_id, a.hobt_id,

b.schema_id, c.name as ‘schema_name’, 

a.index_id, b.create_date, b.modify_date

FROM  sys.partitions AS a INNER JOIN

sys.objects AS b ON a.object_id = b.object_id

INNER JOIN sys.schemas AS c On c.schema_id = b.schema_id              

WHERE LOWER(b.name) = ‘yourPartitionedTableName’

–pull only first index for a simpler view

and a.index_id < 2

ORDER BY b.name, partition_number;

 

— =============================================

–Helpful info for a deeper dive

— =============================================

 

SELECT * FROM SYS.partition_range_values ;

SELECT * from sys.partitions;

SELECT * FROM SYS.partition_functions;

SELECT * FROM sys.partition_schemes;

SELECT * from sys.schemas;

SELECT * FROM sys.filegroups;

 

–query sys.partitions to view and verify that the table contains partitions as expected

SELECT * FROM sys.partitions where OBJECT_NAME(Object_Id)=‘yourPartitionedTableName’;

SELECT * FROM sys.objects where OBJECT_NAME(Object_Id)=‘yourPartitionedTableName’;