Sqlserver的partition table的switch table的前提条件

在sqlserver2k5中可以将一个表转成一个分区表的分区,也可以将分区表的一个分区中的数据转到一个单独的表中。但是在使用alter table  switch to 的时候,是有些前提条件的,而且我在用的时候遇到了些问题,现记录于此,以备日后之用。

? Every index for the partition table must be a partitioned index.
? The new table must have the same columns (excluding identity columns), indexes, and
constraints (including foreign keys) as the partition table, except that the new table
cannot be partitioned.
? The source partition table cannot be the target of a foreign key.
? Neither table can be published using replication, or have schema-bound views.
? The new table must have Check constraint restricting the data range to the new
partition, so SQL Server doesn’t have to re-verify the data range.
? Both the stand-alone table and the partition position that will receive the stand-alone
table must be on the same filegroup.
? The receiving partition must be empty.

这是我从看的书上摘下来的,因为我懒得写自己的了。我没有碰到外键的问题,我主要简单说说我的经过。

1 先改动分区表的其他非分区索引,要在其中添加上用来分区的一列,使这些索引也都可以被改成分区索引,然后将这些索引都改成分区索引。
2 给分区表设置一个空的分区,设置下一个使用的文件组,然后split分区函数,设置新的分区。
3 修改单独表所有的索引,使其设置和分区表上的索引完全一样,包括存储的文件组(要设置成和分区表刚设置的用来转换的新分区相的文件组)
4 还要对单独表用来分区的索引列设置check约束,设置的内容要与分区表新的分区使用的分区条件相符。(这只针对于从单独表转换成分区表的一个分区,从分区将数据转到一个单独表则不需要在单独表中设置check约束)

以上设置好后,就可以使用alter table stand_ alone_ table switch to partition_table partition partition_number
或者alter table partition_table swtich partition partition_num to stand_alone_table了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值