简体   繁体   English

分区切换后,SQL Server表分区无法删除文件组

[英]SQL Server Table Partitioning Cannot drop Filegroup after Partition Switch

I have a huge table with around 110 partitions. 我有一张约110个分区的大桌子。 I wish to archive the oldest partition and drop the FileGroup. 我希望归档最早的分区并删除FileGroup。 Following is the strategy I adopted. 以下是我采用的策略。

  1. Created an exact empty table tablename_archive and met all partitioning requirements. 创建了一个精确的空表tablename_archive并满足所有分区要求。

  2. Perform Partition switch 执行分区切换

     ALTER TABLE tablename SWITCH PARTITION 1 TO tablename_archive PARTITION 1 
  3. After verifying the switch (partition swap) , I dropped the archived table. 在验证了开关(分区交换)之后,我删除了存档表。

  4. Merged the Partition function using the first boundary value as follows 使用第一个边界值合并分区函数,如下所示

     ALTER PARTITION FUNCTION YMDatePF2 () MERGE RANGE ('2012-01-01 00:00:00.000') 

Although there is no data now on FG, when I try to drop the File or FG it errors out saying. 尽管现在FG上没有数据,但是当我尝试删除File或FG时,会出现错误提示。

    The file 'XXXXXXXX' cannot be removed because it is not empty.

    The filegroup 'XXXXXXXX' cannot be removed because it is not empty.

Is there any change I need to make it to Partition scheme too, after merging the function. 合并功能后,我是否还需要对分区方案进行任何更改。

Please let me know if you need any more details. 如果您需要更多详细信息,请告诉我。

You can never remove the first (or only) partition from a RANGE RIGHT partition function (or conversely, the last (or only) partition of a RANGE LEFT function). 您永远不能从RANGE RIGHT分区功能(或相反, RANGE LEFT函数的最后一个(或唯一)分区)中删除第一个(或唯一)分区。 The first (or last if RANGE LEFT ) filegroup from the underlying partition schemes can never be removed from the schemes either. 基础分区方案中的第一个(或最后一个,如果是RANGE LEFT )文件组也永远不能从方案中删除。 Remember you have one more partition, and partition scheme filegroup mapping, than partition boundaries. 请记住,分区和分区方案文件组映射比分区边界多。

If your intent was to archive January 2012 data, you should have switched partition 2 rather than 1 because the first partition contained data less than '2012-01-01 00:00:00.000'. 如果您打算归档2012年1月的数据,则应该切换分区2而不是分区1,因为第一个分区包含的数据少于'2012-01-01 00:00:00.000'。 Now that the second partition has been merged, the first partition (and the first filegroup) contains data less than '2012-02-01T00:00:00.000', which includes January 2012 data. 现在,第二个分区已合并,第一个分区(和第一个文件组)包含的数据小于'2012-02-01T00:00:00.000',其中包括2012年1月的数据。

With a RANGE RIGHT sliding window, it is best to plan to keep the first filegroup empty. 使用RANGE RIGHT滑动窗口时,最好计划将第一个文件组保留为空。 You could used the PRIMARY filegroup or a dummy one with no files for that purpose. 为此,您可以使用PRIMARY文件组或没有文件的虚拟文件组。 See Table Partitioning Best Practices . 请参阅表分区最佳实践

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM