Common SQL Server partition addition and deletion Algorithms

Source: Internet
Author: User

First, add a data table to a partition 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), partition Column
@ SonIsPart tinyint = 1, whether the table to be added is partitioned
The algorithm is as follows:
Obtains the value of the partition column in the source table;
Add the uniqueness restriction of partition column values to the source table;
Then, determine whether a partition can store the table. If it does not exist, return;
Create the same index as the target table on the source table;
Now, the source table and target table have the same structure. The content of the source table can exist in the target partition, And the alter table switch is used to complete the partition;
Algorithm used to delete a partition
[Dbo]. [SP_Helper_Partition_Delete]
@ SrcTable nvarchar (256): delete partitions from the table.
@ IdxOnTable nvarchar (1024), the index creation statement for this table
@ Part_func nvarchar (256), partition function name
@ PartCol nvarchar (256), partition Column
@ PartIndex int: Index of the partition to be deleted
@ IdxIsPart tinyint whether the index is partitioned on another Partition Function
The algorithm is as follows:
First, copy the table structure of a temporary table according to the table structure of the source table;
Obtains the Boundary Value of the partition to be deleted;
Create restrictions on temporary tables;
Create an index on the table;
Switches a specified partition to a temporary table using alter switch;
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.