Refer to the official documentation:
Https://docs.microsoft.com/zh-cn/sql/t-sql/statements/create-partition-function-transact-sql
Default is left
Left: The first value belongs to the first table, corresponding to the <=
Rigth: The first value belongs to the second table, corresponding to a <
If the data is partitioned on a yearly basis, the right option and January 1 per year are appropriate. Such as:
CREATE PARTITION FUNCTION [myDateRangePF1] (datetime) as RANGE right for VALUES ('20030101 ', '20040101 ');
This has three zones: [0,20030101)
,[20030101, 20040101)
,[20040101
,999909999
)
Examplesa. Creating a RANGE left partition function in an int column
The following partition function would partition a table or index into four partitions.
TSQL
CREATE PARTITION FUNCTION myRangePF1 (int) AS RANGE LEFT FOR VALUES (1, 100, 1000);
The following table shows how a table, uses this partition function on partitioning column col1 would is part itioned.
Partition |
1 |
2 |
3 |
4 |
Values |
col1 <=1 |
col1 > 1 col1 <=100 |
col1 > 100 col1 <=1000 |
col1 >1000 |
B. Creating a RANGE right partition function in an int column
The following partition function uses the same values for boundary_value [ ,... n ] as the Previous example, except it specifies RANGE right.
TSQL
CREATE PARTITION FUNCTION myRangePF2 (int) AS RANGE RIGHT FOR VALUES (1, 100, 1000);
The following table shows how a table, uses this partition function on partitioning column col1 would is part itioned.
Partition |
1 |
2 |
3 |
4 |
Values |
col1 <1 |
col1 >= 1 and col1 <100 |
col1 >= 100 and col1 <1000 |
col1 >=1000 |
C. Creating a RANGE right partition function on a datetime column
The following partition function partitions a table or index into a-partitions, one for each month of a year ' s worth of V Alues in a datetime column.
TSQL
CREATE PARTITION FUNCTION [myDateRangePF1] (datetime) AS RANGE RIGHT FOR VALUES (‘20030201‘, ‘20030301‘, ‘20030401‘, ‘20030501‘, ‘20030601‘, ‘20030701‘, ‘20030801‘, ‘20030901‘, ‘20031001‘, ‘20031101‘, ‘20031201‘);
The following table shows how a table or index it uses this partition function on partitioning column Datecol w Ould be partitioned.
Partition |
1 |
2 |
... |
| One
| A
Values |
Datecol <February 1, 2003 |
datecol >= February 1, 2003 and Datecol <March 1, 2003 |
|
datecol >= November 1, 2003 and col1 <December 1, 2003 |
Datecol >=December 1, 2003 |
MSSQLServer the left and right values of partitioned tables