Home > Database > Mysql Tutorial > body text

SQLServer 通用的分区增加和删除的算法

WBOY
Release: 2016-06-07 17:58:45
Original
1053 people have browsed it

本算法默认分去函数中已经包含了足够多的分区。不需要我们去动态的创建分区。

首先是将一个数据表加入到分区表的方法:
[dbo].[SP_Helper_Partition_Add]
@SrcTable nvarchar(256), 待加入的表
@DestTable nvarchar(256), 目标表
@idxOnDest nvarchar(1024), 目标表上的索引创建语句
@Partition_func_name nvarchar(256), 分区函数
@PartCol nvarchar(256), 分区的列
@SonIsPart tinyint=1, 待加入的表是否分区
算法如下:
获取到源表的分区列的值;
在源表上加上分区列值的唯一性限制;
然后确定是否有一个分区恰好能存放这个表;如果不存在,则返回;
在源表上创建和目标表一样的索引;
现在源表和目标结构一致,源表的内容能够存在目标分区上,使用alter table switch完成分区;
删除一个分区的算法
[dbo].[SP_Helper_Partition_Delete]
@SrcTable nvarchar(256), 从该表中删除分区
@IdxOnTable nvarchar(1024), 该表上的索引创建语句
@Part_func nvarchar(256), 分区函数名
@PartCol nvarchar(256), 分区列
@PartIndex int, 待删除分区的索引
@IdxIsPart tinyint 索引是否在另一个分区函数上分区
算法如下:
首先根据源表的表结构复制一分临时表的表结构;
获取待删除分区的边界值;
在临时表上创建限制;
在这个表上创建索引;
将指定分区使用alter switch交换到临时表上;
删除临时表
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!