我创建了一个基于DateTime DataType的分区函数,下面是分区功能的脚本及其相应的分区方案。
CREATE PARTITION FUNCTION [VZDArchiveDatePartition](datetime) AS RANGE LEFT FOR VALUES
(N'2011-07-01T00:00:00.000', N'2011-08-01T00:00:00.000', N'2011-09-01T00:00:00.000',
N'2011-10-01T00:00:00.000', N'2011-11-01T00:00:00.000', N'2011-12-01T00:00:00.000',
N'2012-01-01T00:00:00.000', N'2012-02-01T00:00:00.000', N'2012-03-01T00:00:00.000',
N'2012-04-01T00:00:00.000', N'2012-05-01T00:00:00.000', N'2012-06-01T00:00:00.000')
GO
CREATE PARTITION SCHEME [VZDArchivePartitionScheme] AS PARTITION [VZDArchiveDatePartition] TO
([PRIMARY], [JulyFG], [AugFG], [SepFG], [OctFG], [NovFG], [DecFG], [Jan12FG],
[Feb12FG], [Mar12FG], [Apr12FG], [May12FG], [Jun12FG])
GO
在上面的Partition FUnction中,我使用1个月作为范围值。现在我想将分区范围从月改为季度。 请建议如何更改分配给多个表的现有功能。
答案 0 :(得分:0)
您可以合并分区(请参阅http://msdn.microsoft.com/en-us/library/ms186307.aspx以获取解释),但考虑到要合并的分区数和多个表,您可能最好创建新的分区方案并使用以下方法删除和重新创建索引新方案。
答案 1 :(得分:0)
-- First merge two months into the third one
ALTER PARTITION FUNCTION VZDArchiveDatePartition() MERGE RANGE (N'2011-08-01T00:00:00.000');
ALTER PARTITION FUNCTION VZDArchiveDatePartition() MERGE RANGE (N'2011-09-01T00:00:00.000');
-- Then shrink the files and delete them
DBCC SHRINKFILE (N'AugFG' , 1) -- Ensure that 0 used, 0 estimated values are returned
DBCC SHRINKFILE (N'SepFG' , 1) -- Ensure that 0 used, 0 estimated values are returned
-- At the end, deleting the files and filegroups used might be an idea
ALTER DATABASE [xxx] REMOVE FILE [AugFG]
ALTER DATABASE [xxx] REMOVE FILEGROUP [AugFG]
ALTER DATABASE [xxx] REMOVE FILE [SepFG]
ALTER DATABASE [xxx] REMOVE FILEGROUP [SepFG]