sqlserver 现有订阅发布创建表分区

1,停掉要分区表的发布
sqlserver》本地发布》对应发布属性》项目》要分区的表
2,给表进行分区  
创建文件组
alter database new_HouseRent add filegroup  FG01;
alter database new_HouseRent add filegroup  FG02;
alter database new_HouseRent add filegroup  FG03;
alter database new_HouseRent add filegroup  FG04;
alter database new_HouseRent add filegroup  FG05;
alter database new_HouseRent add filegroup  FG06;
alter database new_HouseRent add filegroup  FG07;
alter database new_HouseRent add filegroup  FG08;
alter database new_HouseRent add filegroup  FG09;
alter database new_HouseRent add filegroup  FG10;
alter database new_HouseRent add filegroup  FG11;

alter database new_HouseRent add filegroup  FG12;

3,创建数据文件到文件组
alter database new_HouseRent add file (name='new_HouseRent01',filename=N'F:\tmp\data\new_HouseRent01.ndf',size=5Mb,filegrowth=5mb) to filegroup FG01;
alter database new_HouseRent add file (name='new_HouseRent02',filename=N'F:\tmp\data\new_HouseRent02.ndf',size=5Mb,filegrowth=5mb) to filegroup FG02;
alter database new_HouseRent add file (name='new_HouseRent03',filename=N'F:\tmp\data\new_HouseRent03.ndf',size=5Mb,filegrowth=5mb) to filegroup FG03;
alter database new_HouseRent add file (name='new_HouseRent04',filename=N'F:\tmp\data\new_HouseRent04.ndf',size=5Mb,filegrowth=5mb) to filegroup FG04;
alter database new_HouseRent add file (name='new_HouseRent05',filename=N'F:\tmp\data\new_HouseRent05.ndf',size=5Mb,filegrowth=5mb) to filegroup FG05;
alter database new_HouseRent add file (name='new_HouseRent06',filename=N'F:\tmp\data\new_HouseRent06.ndf',size=5Mb,filegrowth=5mb) to filegroup FG06;
alter database new_HouseRent add file (name='new_HouseRent07',filename=N'F:\tmp\data\new_HouseRent07.ndf',size=5Mb,filegrowth=5mb) to filegroup FG07;
alter database new_HouseRent add file (name='new_HouseRent08',filename=N'F:\tmp\data\new_HouseRent08.ndf',size=5Mb,filegrowth=5mb) to filegroup FG08;
alter database new_HouseRent add file (name='new_HouseRent09',filename=N'F:\tmp\data\new_HouseRent09.ndf',size=5Mb,filegrowth=5mb) to filegroup FG09;
alter database new_HouseRent add file (name='new_HouseRent10',filename=N'F:\tmp\data\new_HouseRent10.ndf',size=5Mb,filegrowth=5mb) to filegroup FG10;
alter database new_HouseRent add file (name='new_HouseRent11',filename=N'F:\tmp\data\new_HouseRent11.ndf',size=5Mb,filegrowth=5mb) to filegroup FG11;
alter database new_HouseRent add file (name='new_HouseRent12',filename=N'F:\tmp\data\new_HouseRent12.ndf',size=5Mb,filegrowth=5mb) to filegroup FG12;


4, 创建分区函数(划分分区边界)
create partition function [partition_byid] (int) as range right for values  
(5000000,6000000,9000000,12000000,15000000,18000000,21000000,24000000,27000000,30000000,33000000,36000000

5 创建分区方案
CREATE PARTITION SCHEME [partition_byid] AS PARTITION [partition_byid]  
TO ([primary],[FG01], [FG02], [FG03], [FG04], [FG05],[FG06], [FG07], [FG08], [FG09], [FG10], [FG11], [FG12])  


6, 复用分区组
ALTER PARTITION SCHEME [partition_byid] NEXT USED [FG01]  
alter partition function [partition_byid]()  SPLIT RANGE (39000000)  ;
ALTER PARTITION SCHEME [partition_byid] NEXT USED [FG02]  
alter partition function [partition_byid]()  SPLIT RANGE (42000000)  ;
ALTER PARTITION SCHEME [partition_byid] NEXT USED [FG03]  
alter partition function [partition_byid]()  SPLIT RANGE (45000000)  ;
ALTER PARTITION SCHEME [partition_byid] NEXT USED [FG04]  
alter partition function [partition_byid]()  SPLIT RANGE (48000000)  ;
ALTER PARTITION SCHEME [partition_byid] NEXT USED [FG05]  
alter partition function [partition_byid]()  SPLIT RANGE (51000000)  ;
ALTER PARTITION SCHEME [partition_byid] NEXT USED [FG06]  
alter partition function [partition_byid]()  SPLIT RANGE (54000000)  ;
ALTER PARTITION SCHEME [partition_byid] NEXT USED [FG07]  
alter partition function [partition_byid]()  SPLIT RANGE (57000000)  ;
ALTER PARTITION SCHEME [partition_byid] NEXT USED [FG08]  
alter partition function [partition_byid]()  SPLIT RANGE (60000000)  ;
ALTER PARTITION SCHEME [partition_byid] NEXT USED [FG09]  
alter partition function [partition_byid]()  SPLIT RANGE (63000000)  ;
ALTER PARTITION SCHEME [partition_byid] NEXT USED [FG10]  
alter partition function [partition_byid]()  SPLIT RANGE (66000000)  ;
ALTER PARTITION SCHEME [partition_byid] NEXT USED [FG11]  
alter partition function [partition_byid]()  SPLIT RANGE (69000000)  ;
ALTER PARTITION SCHEME [partition_byid] NEXT USED [FG12]  
alter partition function [partition_byid]()  SPLIT RANGE (72000000)  ;

7,开始分区
表 》存储 》创建分区》选择分区函数》选择分区方案

8,重新发布
选择相关发布》属性》项目》添加表》修改分区表复制属性


9,重新初始化所有订阅
查看快照代理状态 ok


猜你喜欢

转载自blog.csdn.net/lyk_for_dba/article/details/78115414