You can use the sys.partition_schemes
system catalog view to return a list of partition schemes in SQL Server.
Example
Here’s an example to demonstrate.
SELECT * FROM sys.partition_schemes;
Result:
+-----------------------+-----------------+--------+------------------+--------------+-------------+---------------+ | name | data_space_id | type | type_desc | is_default | is_system | function_id | |-----------------------+-----------------+--------+------------------+--------------+-------------+---------------| | MoviesPartitionScheme | 65606 | PS | PARTITION_SCHEME | 0 | 0 | 65542 | +-----------------------+-----------------+--------+------------------+--------------+-------------+---------------+
To save you from scrolling sideways, here it is again using vertical output:
name | MoviesPartitionScheme data_space_id | 65606 type | PS type_desc | PARTITION_SCHEME is_default | 0 is_system | 0 function_id | 65542
In this case, I only have one partition scheme, and so that is listed.
This view actually inherits its first six columns from the sys.data_spaces
view.
Find the Index
You can modify the query in order to provide more meaningful information.
Here’s an example where I join it with sys.indexes
to return the relevant index, table, and schema.
SELECT
object_schema_name(i.object_id) AS [Schema],
object_name(i.object_id) AS [Object],
i.name AS [Index],
s.name AS [Partition Scheme]
FROM sys.indexes i
INNER JOIN sys.partition_schemes s ON i.data_space_id = s.data_space_id;
Result:
+----------+----------+------------------------------+-----------------------+ | Schema | Object | Index | Partition Scheme | |----------+----------+------------------------------+-----------------------| | dbo | Movies | PK__Movies__4BD2941AD44D2FCF | MoviesPartitionScheme | +----------+----------+------------------------------+-----------------------+
Result using vertical output:
Schema | dbo Object | Movies Index | PK__Movies__4BD2941AD44D2FCF Partition Scheme | MoviesPartitionScheme
The sys.partition_schemes
view requires membership in the public role.