Thursday 26 September 2013

Query Which Tables are Partitioned


List out which tables are partitioned, and what partition scheme and partition function they use:

SELECT t.name AS TableName, ps.name AS PartitionScheme,
    ps.data_space_id, pf.name AS PartitionFunction, pf.function_id
FROM sys.TABLES t
    JOIN sys.indexes i ON t.object_id = i.object_id
    JOIN sys.partition_schemes ps ON i.data_space_id = ps.data_space_id
    JOIN sys.partition_functions pf ON ps.function_id = pf.function_id
WHERE i.index_id < 2

For a given partition function, list each of the boundary values

SELECT r.boundary_id, r.VALUE FROM sys.partition_range_values r
    JOIN sys.partition_functions pf ON r.function_id = pf.function_id
WHERE pf.name = 'fnQuarters'        -- partition function name
ORDER BY r.VALUE


No comments: