HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

How do I add values to partition function and scheme?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
partitionschemeandfunctionhowvaluesadd

Problem

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.

Solution

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.

Code Snippets

ALTER PARTITION SCHEME [PartitionByPeriodScheme] NEXT USED [FactsAfter2016_2];
ALTER PARTITION FUNCTION [PartitionByPeriodFunction]() SPLIT RANGE 20171231;

Context

StackExchange Database Administrators Q#133046, answer score: 4

Revisions (0)

No revisions yet.