博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mssqlserver分区表的左值与右值
阅读量:4946 次
发布时间:2019-06-11

本文共 2172 字,大约阅读时间需要 7 分钟。

参考官方文档:

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.

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.

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.

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.

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.

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

转载于:https://www.cnblogs.com/81/p/7436666.html

你可能感兴趣的文章
Python函数篇(1)-函数中的形参与实参(已更新)
查看>>
WCF(二) 使用配置文件实现WCF应用程序
查看>>
【CodeForces 803 C】Maximal GCD(GCD+思维)
查看>>
python 去掉换行符或者改为其他方式结尾的方法(end='')
查看>>
数据模型(LP32 ILP32 LP64 LLP64 ILP64 )
查看>>
REST构架风格介绍:状态表述转移
查看>>
广告弹力球效果
查看>>
学习总结(三十五)
查看>>
[转载]115个Java面试题和答案
查看>>
[笔记] 易错点集合
查看>>
使用gnuplot对tpcc-mysql压测结果生成图表
查看>>
微信事件推送接口(原创总结)
查看>>
ubuntu server下安装VMware【原创】
查看>>
浅谈session与cookie之间的联系
查看>>
struct {0}初始化
查看>>
c++ operator
查看>>
apache 添加 ssl_module
查看>>
java小技巧
查看>>
POJ 3204 Ikki's Story I - Road Reconstruction
查看>>
getQueryString
查看>>