concept partition function in category sql

appears as: partition functions, partition function, partition function, The partition function, A partition function
SQL Server MVP Deep Dives

This is an excerpt from Manning's book SQL Server MVP Deep Dives.

How the partition function works

So how does this all work? As figure 1 showed, it all starts with the partition function. This is a special type of function used in table partitioning, and is unlike other T-SQL functions in several ways. Like other functions, each partition function is scoped to the database it’s created in. Although the partition function is a user-created database object, it’s not visible by ordinary means in Management Studio; you can find partition functions, along with partition schemes, in the Storage node for each database. The reason is because the partition function is a special database object, not found in the sys.sysobjects table like other user-created and system functions.

What a partition function does is define the boundaries of a partitioned table based on the data type of the partitioning key of the table. The partition function splits up the range of all possible values that might be in the partitioning key of a table, and assigns each to a possible partition.

It’s important to see that the partition function operates in a flexible way that can change over time. This is critical: you use the SPLIT and MERGE operations to add and remove partitions in a table by adding and removing partitions in the table’s partition function.

For example, you can create a partition function using the following syntax:

CREATE PARTITION FUNCTION PFNExample1_Left (int)
AS RANGE LEFT FOR VALUES (10, 20, 30);

This code creates a partition function that