Sql-server – How to add values to partition function and scheme

partitioningsql server

We have a partition function defined as

CREATE PARTITION FUNCTION [PartitionByPeriodFunction](int) 
AS RANGE LEFT 
FOR VALUES (20101228, ... , 20161227) 

where each date is the first date of our fiscal period.

We have a partition scheme defined as

CREATE PARTITION SCHEME [PartitionByPeriodScheme] 
AS PARTITION [PartitionByPeriodFunction] 
TO ([FactsBefore2011], ..., [FactsP201612], [FactsAfter2016])

I want to add more periods to the partition function and more filegroups to the partition scheme – what is the best way to do this?

I have read to drop and recreate the function and scheme – will the dependent objects allow that? I am unsure how to use split since I am not wanting to split 20161227 but rather continue the pattern.

Best Answer

You can modify the partition scheme and function to effectively add a new partition.

ALTER PARTITION SCHEME [PartitionByPeriodScheme] NEXT USED [FactsAfter2016_2];

Follow this up with:

ALTER PARTITION FUNCTION [PartitionByPeriodFunction]() SPLIT RANGE 20171231;

This will add a range between 20161227 and 20171231, which will be placed on [FactsAfter2016_2].

As always, try this on a non-production system first.