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)
20030101)
[20030101, 20040101), [20040101, 999909999)
20030101, 20040101)
20040101)
[20040101, 999909999)
[20040101, 999909999)
20040101, 999909999
20040101
20040101
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.
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.
Partition | 1 | 2 | 3 | 4 |
---|---|---|---|---|
Values | col1 <= 1 |
col1 > 1 AND col1 <= 100 |
col1 > 100 AND col1 <=1000 |
col1 > 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.
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.
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 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');
The following table shows how a table or index that uses this partition function on partitioning column datecol would be partitioned.
Partition | 1 | 2 | ... | 11 | 12 |
---|---|---|---|---|---|
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 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本