I have a large table that is already partitioned by an identifier (CustomerId). I have created new customers, and want to add new partitions to the table, and want to confirm the correct way to do this. My predecessor set this up and is no longer available so I cannot confirm.
There are currently partitions for 60 distinct CustomerIds (let's say 1-60), and a filegroup and file for each. I have created new filegroups and files for the new customers (61-68) and need to partition the existing data already in this table. So, the data that's already in the table, with customerId 61-68 needs to be moved into separate partitions.
I tried to use the partition wizard, but couldn't find an option for what I wanted. As far as I can tell, I need to run something like:
ALTER PARTITION SCHEME PS_Details NEXT USED Filegroup61
ALTER PARTITION FUNCTION PF_Details () SPLIT RANGE (61)
I'm looking for someone to point me in the right direction as to best practice for this sort of thing. Do I take the data out of the table, into a new table stored in the Filegroup61 then switch the partition in? Not really sure how to approach this.
Best Answer
Splitting a non-empty partition requires about 4x logging as normal DML. Assuming the table and indexes are aligned, you can avoid excessive logging with large tables by creating a partitioned staging table with the original boundaries. Then switch in the problem partition, split the empty partitions of the original function, repartition the staging table, and switch the remediated partitions back in. Below is an example script. You'll need to tweak this if you use a
RANGE LEFT
partition function and specify your actual filegroups.