我可能会选择这样的东西。我假设您按递增顺序插入数据键,而不返回或对其进行任何更新。
在此示例中,我假设您最早的日期键是 2015 年 1 月。
创建一个没有聚集索引的测试表:
create table dbo.test(id int identity(0, 1) primary key nonclustered, datekey int, data nchar(2000))
go
insert into test(datekey, data) values
(20150125, ''), (20150120, ''), (20150118, ''), (20150118, ''), (20150118, '')
, (20150205, ''), (20150215, ''), (20150215, ''), (20150215, ''), (20150215, '')
, (20150305, ''), (20150315, '')
创建文件组和文件:
Alter Database [Test] Add Filegroup [Part_201501]
Alter Database [Test] Add Filegroup [Part_201502]
Alter Database [Test] Add Filegroup [Part_201503]
Alter Database [Test] Add FILE ( NAME = N'Part_201501', FILENAME = N'...\Part_201501.ndf' , SIZE = 5120KB , FILEGROWTH = 1024KB ) TO Filegroup [Part_201501]
Alter Database [Test] Add FILE ( NAME = N'Part_201502', FILENAME = N'...\Part_201502.ndf' , SIZE = 5120KB , FILEGROWTH = 1024KB ) TO Filegroup [Part_201502]
Alter Database [Test] Add FILE ( NAME = N'Part_201503', FILENAME = N'...\Part_201503.ndf' , SIZE = 5120KB , FILEGROWTH = 1024KB ) TO Filegroup [Part_201503]
从 20150201(即 01-2015)之前的所有内容开始创建函数:
Create Partition Function DateKeyPartFunction (int)
as Range Right For Values (20150201, 20150301)
请注意,我不能像 201501 这样按部分数据键进行分区。这就是为什么我按下个月的第一天进行分区的原因。
所有 datekey >= 20150201 和
创建方案:
Create Partition Scheme DateKeyPartScheme as Partition DateKeyPartFunction
To ([Part_201501], [Part_201502], [Part_201503])
创建聚集索引:
Create Clustered Index IDX_Part On dbo.Test(datekey) On DateKeyPartScheme(datekey);
如果您有一个集群主键。您必须将其替换为非集群 PK(+删除/添加 FK)。
这不会改变您的表格类型。
一旦到了四月,你只需要添加一个新的 Part_201504 文件组并在 20150401 上拆分函数...