SQL Server common algorithm for partitioning additions and deletions _mssql

Source: Internet
Author: User
The first is the way to add a datasheet to a partitioned table:
[dbo]. [Sp_helper_partition_add]
@SrcTable nvarchar (256), table to be added
@DestTable nvarchar (256), target table
@idxOnDest nvarchar (1024), index creation statement on the target table
@Partition_func_name nvarchar (256), partition function
@PartCol nvarchar (256), partitioned columns
@SonIsPart tinyint=1, whether the table to be added is partitioned
The algorithm is as follows:
Gets the value of the partition column to the source table;
The uniqueness limit of the partition column value on the source table;
Then determine if there is a partition that exactly holds the table, or return if it does not exist;
Create an index on the source table that is the same as the target table;
Now the source table and target structure are consistent, the contents of the source table can exist on the target partition, and the ALTER TABLE switch is used to complete the partition;
To delete an algorithm for a partition
[dbo]. [Sp_helper_partition_delete]
@SrcTable nvarchar (256), removing partitions from this table
@IdxOnTable nvarchar (1024), the index creation statement on the table
@Part_func nvarchar (256), name of the partition function
@PartCol nvarchar (256), partition column
@PartIndex int, the index of the partition to be deleted
@IdxIsPart whether the tinyint index is partitioned on another partition function
The algorithm is as follows:
First, the table structure of a temporary table is copied according to the table structure of the source table.
Gets the boundary value of the partition to be deleted;
Create a constraint on a temporary table;
Create an index on this table;
Swap the specified partition with ALTER switch to the temporary table;
Delete temporary table
Related Article

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.