有幾個關於分區的問題

來源:互聯網
上載者:User

有幾個關於分區的問題,希望大家幫忙了
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

 

-----------------------------

如果主健只有一列時直接改

 
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
-----------------------------------
如果是into產生的表,這樣用 
use TEMPDBgoselect * into T from sysobjectsgocreate partition function F_Partition(int)as range right for values(1,100,1000)goCREATE PARTITION SCHEME  P_schemaas partition F_Partition  ALL to ([PRIMARY])goalter table T alter column ID int not nullalter table T add constraint PK_T primary key (ID) on P_schema(ID) select * from TDROP TABLE TDROP  PARTITION SCHEME  P_schemaDROP partition function  F_Partition
http://topic.csdn.net/u/20090803/15/225c1920-e2a0-417a-9bd8-658644b9b96c.html?35493

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.