撤消表分区
我有一个表“X”,并执行了以下操作
- CREATE PARTITION FUNCTION PF1(INT) AS RANGE LEFT FOR VALUES (1, 2, 3, 4)
- CREATE PARTITION SCHEME PS1 AS PARTITION PF1 ALL TO ([PRIMARY])
- CREATE CLUSTERED INDEX CIDX_X ON X(col1) ON PS1(col1)
这 3 个步骤创建了我拥有的数据的 4 个逻辑分区。
我的问题是,如何将此分区恢复到原始状态?
I have a table 'X' and did the following
- CREATE PARTITION FUNCTION PF1(INT) AS RANGE LEFT FOR VALUES (1, 2, 3, 4)
- CREATE PARTITION SCHEME PS1 AS PARTITION PF1 ALL TO ([PRIMARY])
- 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过2天的连续搜索
步骤:
DROP INDEX CIDX_X on X
/* drop the clustered */CREATE CLUSTERED INDEX CIDX_X1 ON X(col1) ON [PRIMARY]
/*在表上创建另一个聚集索引以将其从分区方案中释放出来;在这里,“ON [primary]”部分是从表中删除分区方案的关键! */After 2 days of continuous searching
The Steps:
DROP INDEX CIDX_X on X
/* drop the clustered */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 ! */DROP PARTITION SCHEME PS1
DROP PARTITION FUNCTION PF1
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 */我发现应该在 Storm 给出的答案中添加一些额外的步骤,因为,有一些点,例如...在删除聚集索引之前,需要删除该发布,因为它不允许在此之前删除聚集索引删除这些分区方案和分区函数后,需要重新创建,并且还需要再次开始发布。
注意:我使用的是 SQL 2012
主键通常是最常用的聚集约束,因此无论我在哪里使用主键,请考虑这些步骤也适用于聚集约束。另外,PS = 分区方案,PF = 分区函数。
<块引用>
以上所有内容,使用 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 INDEX CIDX_X1 ON tablename
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.
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 INDEX CIDX_X1 ON tablename