/*第一步:创建分区函数*/
Create partition function Part_func_Bag(varchar(20)) as range right
/*正式区间for values(N'01100923909760', N'01100936207030', N'6311001806524',N'92451400060101');*/
for values(N'91701311710807', N'07201280707101', N'8011011089884',N'80241001430714');
go
select * from Bag where
BagCode in(N'91701311710807', N'07201280707101', N'8011011089884',N'80241001430714')
/*第二步:创建文件组和文件*/
alter database ZXAutoCode add filegroup [Bag_1];
alter database ZXAutoCode add filegroup [Bag_2];
alter database ZXAutoCode add filegroup [Bag_3];
alter database ZXAutoCode add filegroup [Bag_4];
go
alter database ZXAutoCode add file (name = Bag1_data,filename = 'E:MSSQLTESTDATABag1_data.ndf',size = 3MB) to filegroup [Bag_1];
alter database ZXAutoCode add file (name = Bag2_data,filename = 'E:MSSQLTESTDATABag2_data.ndf',size = 3MB) to filegroup [Bag_2];
alter database ZXAutoCode add file (name = Bag3_data,filename = 'E:MSSQLTESTDATABag3_data.ndf',size = 3MB) to filegroup [Bag_3];
alter database ZXAutoCode add file (name = Bag4_data,filename = 'E:MSSQLTESTDATABag4_data.ndf',size = 3MB) to filegroup [Bag_4];
go
/*第三步:创建分区方案并关联到分区函数*/
Create partition scheme Part_func_Bag_scheme as partition Part_func_Bag to ([Bag_1],[Bag_2],[Bag_3],[Bag_4],[Primary]);
go
/*第四步 重建索引(删除聚集索引以及需要分区字段的索引后重建该类索引,表被按分区值将分配到各文件组。数据在这一步开始转移。)*/
EXEC sp_helpindex N'Bag' --查看orders中使用的索引
drop index idx_cl_od on Bag;
go
create clustered index idx_cl_od on Bag(bagcode)
on Part_func_Bag_scheme(bagcode);
go