mssqlserver分区表的左值与右值

参考官方文档:

https://docs.microsoft.com/zh-cn/sql/t-sql/statements/create-partition-function-transact-sql

默认是Left

LEFT:第一个值属于第一个表,对应<=

RIGTH: 第一个值属于第二个表,对应<

如果数据按年进行分区,则RIGHT选项且每年的1月1日是合适的。如:

CREATE PARTITION FUNCTION [myDateRangePF1] (datetime)  
AS RANGE RIGHT FOR VALUES ('20030101', '20040101'); 
这个有三个区:[0,20030101), [20030101, 20040101), [20040101, 999909999)

 

 

Examples

A. Creating a RANGE LEFT partition function on an int column

The following partition function will 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 that uses this partition function on partitioning column col1 would be partitioned.

Partition1234
Valuescol1 <= 1col1 > 1 AND col1 <= 100col1 > 100 AND col1 <=1000col1 > 1000

B. Creating a RANGE RIGHT partition function on 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 that uses this partition function on partitioning column col1 would be partitioned.

Partition1234
Valuescol1 < 1col1 >= 1 AND col1 < 100col1 >= 100 AND col1 < 1000col1 >= 1000

C. 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.

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 that uses this partition function on partitioning column datecol would be partitioned.

Partition12...1112
Valuesdatecol < February 1, 2003datecol >= February 1, 2003 AND datecol < March 1, 2003 datecol >= November 1, 2003 AND col1 < December 1, 2003datecol >= December 1, 2003
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值