Monday, April 30, 2007

CREATE PARTITION FUNCTION (Transact-SQL)

CREATE PARTITION FUNCTION (Transact-SQL)

CREATE PARTITION FUNCTION partition_function_name ( input_parameter_type )
AS RANGE [ LEFT RIGHT ]
FOR VALUES ( [ boundary_value [ ,...n ] ] )
[ ; ]



Creating a RANGE LEFT partition function on an int column
The following partition function will partition a table or index into four partitions.
CREATE PARTITION FUNCTION myRangePF1 (int)
AS RANGE LEFT FOR VALUES (1, 100, 1000);



Creating a RANGE RIGHT partition function on a datetime column
The following partition function partitions a table or index into 12 partitions, one for each month of a year's worth of values in a datetime column.
CREATE PARTITION FUNCTION [myDateRangePF1] (datetime)
AS RANGE RIGHT FOR VALUES ('20030201', '20030301', '20030401',
'20030501', '20030601', '20030701', '20030801',
'20030901', '20031001', '20031101', '20031201');