For a partitioned table, how do I determine via T-SQL what is the next partition number that will be used? For example, the switch-in today went into partition number 50. I want to build the new switch-in table to contain the boundary values for partition number 51. I'm currently doing this manually and want to automate it via stored procedures. I'm using SQL Server 2012.
Sql-server – Obtaining the next partition number
partitioningsql serversql-server-2012
Related Question
- Sql-server – Why isn’t partition-level lock escalation the default
- Sql-server – Partition Function with only one value, what does this effect
- Sql-server – How to remove a table partition
- Mysql – Recreate partition in thesql
- Sql-server – Switching a partition on a table with one to many relation
- Sql-server – SQL Server Partition Switch
- SQL Server – No Partition Elimination for Lookup Table Column Values
- PostgreSQL – Understanding Partition Table Behavior
Best Answer
There are a few good DMVs (system views) where you can find this info: sys.partition_functions and sys.partition_schemes can be joined to sys.partition_range_values to get all existing ranges. The number of ranges should be the number of partitions.
The data_space_id of the partition scheme can be joined to that of the index or heap in sys.indexes on the table (sys.tables) that you're interested in.