MSSQLServer the left and right values of partitioned tables

Source: Internet
Author: User
Tags mssqlserver

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.

One A
Partition 1 2 ...
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.