日期:2014-05-17 浏览次数:20586 次
alter database wc
set single_user
with rollback immediate
drop database wc
--1.创建数据库
create database wc
on primary
(
name = wc_data,
filename = 'D:\wc_data.mdf'
)
log on
(
name = wc_log1,
filename = 'd:\wc_log1.ldf'
),
(
name = wc_log2,
filename = 'd:\wc_log2.ldf'
)
go
use wc
go
--4.创建分区函数,3个值,但是会有4个分区
create partition function wcLeftRange(char(6))
as range left for values('201309','201310','201311')
--5.创建分区方案,4个文件组
create partition scheme wcLeftRangeScheme
as partition wcLeftRange
to ([primary],[primary],[primary],[primary])
--6.建表,聚集索引,插入数据
create table temp_UserBill
(
BusinessDate char(6), F1 varchar(100), F2 Varchar(100)
)
create clustered index idx_temp_UserBill on temp_UserBill(BusinessDate)
insert into temp_UserBill
select '201309','aa1','bb1' union all
select '201309','aa2','bb2' union all
select '201310','aa1','bb1' union all
select '201310','aa2','bb2' union all
select '201311','aa1','bb1' union all
select '201311','aa2','bb2' union all
select '201312','aa','bb'
go
--7.要转化为分区表,必须要删除聚集索引
drop index idx_temp_UserBill on temp_UserBill
--8.然后再重新建立一个聚集索引,并且指定:分区方案和分区字段
create clustered index idx_temp_UserBill on temp_UserBill(BusinessDate)
on wcLeftRangeScheme(BusinessDate)
-