六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 31|回复: 0

有几个关于分区的问题

[复制链接]

升级  36.35%

563

主题

563

主题

563

主题

探花

Rank: 6Rank: 6

积分
1727
 楼主| 发表于 2013-2-7 15:00:56 | 显示全部楼层 |阅读模式
有几个关于分区的问题,希望大家帮忙了
1. 表已经存在,能否再应运分区方案呢,如果可以,这么用?
2. sqlserver里能否直接通过执行Select * into 表 from 表2时,也带上分区方案,如果能这样那是方便不过?
可以
1:刪除普通索引
2:刪除主健索引並轉為分區表
3:再恢復主健索引
4:恢復普通索引
use TEMPDB
go
create table t(ID int identity ,Num int not null constraint PK_T primary key(Num,ID))
create index IX_T_Num on T(Num)

go
create partition function F_Partition(int)
as range right for values(1,100,1000)
go
CREATE PARTITION SCHEME P_schema
as partition F_Partition ALL to ([PRIMARY])

go
drop index IX_T_Num on T
alter table T drop constraint PK_T with(Move to P_schema(Num))

alter table t alter column ID int not null

alter table T add constraint PK_T primary key (Num,ID)


select * from T


DROP TABLE T
DROP PARTITION SCHEME P_schema DROP partition function F_Partition
-----------------------------
如果主健只有一列時直接改
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->use TEMPDBgocreate table t(ID int identity constraint PK_T primary key,Num int not null )--只有一個IDcreate index IX_T_Num on T(Num)gocreate partition function F_Partition(int)as range right for values(1,100,1000)goCREATE PARTITION SCHEME  P_schemaas partition F_Partition  ALL to ([PRIMARY])godrop index IX_T_Num on Talter table T drop constraint PK_T with(Move to P_schema(ID))--這里改為IDalter table t alter column ID int  not nullalter table T add constraint PK_T primary key (ID)--改為IDselect * from TDROP TABLE TDROP  PARTITION SCHEME  P_schemaDROP partition function  F_Partition
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表