撤消表分区

发布于 2024-09-04 15:15:12 字数 320 浏览 4 评论 0原文

我有一个表“X”,并执行了以下操作

  1. CREATE PARTITION FUNCTION PF1(INT) AS RANGE LEFT FOR VALUES (1, 2, 3, 4)
  2. CREATE PARTITION SCHEME PS1 AS PARTITION PF1 ALL TO ([PRIMARY])
  3. CREATE CLUSTERED INDEX CIDX_X ON X(col1) ON PS1(col1)

这 3 个步骤创建了我拥有的数据的 4 个逻辑分区。

我的问题是,如何将此分区恢复到原始状态?

I have a table 'X' and did the following

  1. CREATE PARTITION FUNCTION PF1(INT) AS RANGE LEFT FOR VALUES (1, 2, 3, 4)
  2. CREATE PARTITION SCHEME PS1 AS PARTITION PF1 ALL TO ([PRIMARY])
  3. CREATE CLUSTERED INDEX CIDX_X ON X(col1) ON PS1(col1)

this 3 steps created 4 logical partitions of the data I had.

My question is, how do I revert this partitioning to its original state ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怪我鬧 2024-09-11 15:15:12

经过2天的连续搜索

步骤:

  1. DROP INDEX CIDX_X on X /* drop the clustered */
  2. CREATE CLUSTERED INDEX CIDX_X1 ON X(col1) ON [PRIMARY] /*在表上创建另一个聚集索引以将其从分区方案中释放出来;在这里,“ON [primary]”部分是从表中删除分区方案的关键! */
  3. DROP PARTITION SCHEME PS1
  4. DROP PARTITION FUNCTION PF1
  5. DROP INDEX CIDX_X1 ON X /* 删除您创建的虚拟聚集索引,因为它只是创建以将表从分区方案中释放*/

After 2 days of continuous searching

The Steps:

  1. DROP INDEX CIDX_X on X /* drop the clustered */
  2. CREATE CLUSTERED INDEX CIDX_X1 ON X(col1) ON [PRIMARY] /* Create another clustered index on the table to free it from the partitioning scheme; Here, the "ON [primary]" part is key to removing the partition scheme from the table ! */
  3. DROP PARTITION SCHEME PS1
  4. DROP PARTITION FUNCTION PF1
  5. DROP INDEX CIDX_X1 ON X /* drop the dummy clustered index you created, as it was only created to free the table from the partitioning scheme */
独享拥抱 2024-09-11 15:15:12

我发现应该在 Storm 给出的答案中添加一些额外的步骤,因为,有一些点,例如...在删除聚集索引之前,需要删除该发布,因为它不允许在此之前删除聚集索引删除这些分区方案和分区函数后,需要重新创建,并且还需要再次开始发布。

注意:我使用的是 SQL 2012
主键通常是最常用的聚集约束,因此无论我在哪里使用主键,请考虑这些步骤也适用于聚集约束。另外,PS = 分区方案,PF = 分区函数。

一些准备步骤:

  1. 制作一个删除发布脚本
  2. 制作一个创建发布脚本
  3. 识别与分区方案有依赖关系的所有表,并记下它们的主键/聚集索引。此外,记下主键列使用的所有字段(最好为主键或聚集索引生成脚本)
  4. 为受影响的表制作脚本。
  5. 为有问题的 PF 和 PS 制作一个脚本。

    <块引用>

    以上所有内容,使用 SQL Management Studio 右键单击​​“生成脚本”。然后选择删除并创建。

现在,当一切准备就绪时。
1. 删除发布(使用您生成的脚本)
2. 删除与PS 链接的那些表的主键约束。
alter table [tablename] 删除约束 [pk_name]
3. 创建虚拟约束,但使用与已删除的主键中使用的相同字段。 CREATE CLUSTERED INDEX CIDX_X1 ON 表名(field1,field2,field3,field4) ON [PRIMARY]
4.删除分区方案和功能。

DROP PARTITION SCHEME [PartitionSchemeName_PS]
GO

DROP PARTITION FUNCTION [PartitionfunctionName_PF]
GO
  1. 删除虚拟索引
    DROP INDEX CIDX_X1 ON tablename
  2. 添加回聚集索引/主键约束(使用前面提到的生成脚本。
  3. 创建分区函数和分区架构(确保 PS > PF 的元素数量)。其中 PS = PF+2 个元素)
  4. 添加回发布者(使用生成的脚本)

I found that some additional steps should be added to the answer given by Storm, since, there are some points like ... before deleting the clustered index, the publication needs to be dropped because it wont allow the clustered index to get dropped before that and after dropping those partition-scheme and partition function needs to be recreated, and publication also again needs to be started.

Note: I am using SQL 2012
Primary key is normally the most commonly used clustered constraint, so wherever i used primary key, consider that those steps also apply to Clustered constraints too. Also, PS= Partition Scheme, PF = Partition Function.

Some preparatory steps:

  1. Make a drop publication script
  2. Make a create publication script
  3. Identify all tables who have dependencies with the Partition Scheme,and also note down their primary key/clustered index.Also, note down all the fields which the primary key column uses (better to generate the script for primary key or clustered index)
  4. Make a script for tables getting affected.
  5. Make a script for PF and PS that are in question.

    All the above, using SQL Management Studio "generate scripts" upon right click. And choose drop and create.

Now, when everything is ready.
1. Drop the publication (use the script that you generated)
2. Drop the Primary key constraint of those tables which are linked with the PS.
alter table [tablename] drop constraint [pk_name]
3. Make a dummy constraint but use the same fields that you used in that deleted primary key. CREATE CLUSTERED INDEX CIDX_X1 ON tablename(field1,field2,field3,field4) ON [PRIMARY]
4. drop the partition scheme and function.

DROP PARTITION SCHEME [PartitionSchemeName_PS]
GO

DROP PARTITION FUNCTION [PartitionfunctionName_PF]
GO
  1. Drop the Dummy Index
    DROP INDEX CIDX_X1 ON tablename
  2. Add back the Clustered index/primary key constraint(using the generated scripts as mentioned earlier.
  3. Create the Partition function and Partition schema (ensure that the number of elements of PS > PF. where PS = PF+2 elements)
  4. Add back the publisher (use the generated scripts)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文