--建立文件组 create database alex2 on primary (=,=,=,=,=), Filegroup old (=,=,=,=,=), Filegroup first (=,=,=,=,=), Filegroup second (=,=,=,=,=), Filegroup third (=,=,=,=,=%), Filegroup fourth (=,=,=,=,=%) log on (=,=,=,=,=) go --使用数据库 use alex2 go --建立分区函数 --按照必定的条件划分数据 --range left (--,--] (--,--] 分界点的值归左边 --range right (--,--) [--,--) 分界点的值归右边 create partition (datetime) as range right values(,,,) --建立分区方案 --将分区函数区分的范围和文件组对应起来 create partition scheme RateChngDate_Scheme as partition to (Old,First,Second,Third,Fourth) --建立分区表 create table EmpPayHistPart ( EmployeeID int, RateChangeDate datetime, Rate money, PayFrequency tinyint, ModifiedDate datetime )on RateChngDate_Scheme(RateChangeDate) --添加数据 insert into EmpPayHistPart values(,,,,) insert into EmpPayHistPart values(,,,,) insert into EmpPayHistPart values(,,,,) insert into EmpPayHistPart values(,,,,) insert into EmpPayHistPart values(,,,,) --检索分区 select * from EmpPayHistPart where $partition.RateChngDate(RateChangeDate)=select * from EmpPayHistPart where $partition.RateChngDate(RateChangeDate)=select * from EmpPayHistPart where $partition.RateChngDate(RateChangeDate)=select * from EmpPayHistPart where $partition.RateChngDate(RateChangeDate)=select * from EmpPayHistPart where $partition.RateChngDate(RateChangeDate)=select * from EmpPayHistPart where $partition.RateChngDate(RateChangeDate)=select * from EmpPayHistPart where $partition.RateChngDate(RateChangeDate)=select * from EmpPayHistPart ---------------分隔分区 --修改数据库添加文件组 alter database alex2 add filegroup Fifth --修改数据库向文件组中添加文件 alter database alex2 add (=,=,=,=,=) to filegroup Fifth go --修改分区方案 让下一个分区使用Fifth文件组 alter partition scheme RateChngDate_Scheme next used Fifth --修改分区函数 加入一个临界点2002--alter partition () split range () go ---------------------合并分区 --将2008--以后的数据和前一个分区数据合并 --原来是2004--到2008--,--到之后 --如今是2004--到之后 alter partition () merge range() -------------------建立表保存分区 --修改数据库添加文件组Sixth alter database alex2 add filegroup Sixth --修改数据库添加文件到文件组Sixth alter database alex2 add (=,=,=,=,=) to filegroup Sixth go --修改分区方案让下一个分区对应文件组Sixth alter partition scheme RateChngDate_Scheme next used Sixth --分隔数据分区 alter partition () split range () go --建立表来保存分区数据 create table New_EmpPayHistPart ( EmployeeID int, RateChangeDate datetime, Rate money, PayFrequency tinyint, ModifiedDate datetime )on Sixth --将分区6中的数据移动到新表中 alter table EmpPayHistPart partition to New_EmpPayHistPart