轉移表空間步驟

2021-09-30 06:26:00 字數 4727 閱讀 1656

轉移表空間步驟

一、轉移表空間

alter table tab_name move tablespace tabspace_name;

分割槽表alter table table_name move partition  para_name tablespace tablespace_name;

批量生成語句:

select 'alter table '||table_name||' move tablespace tabspace_name;' from user_tables;

二、重建索引

alter index indx_name rebuild online;

seelct 'alter index ''||indx_name||' rebuild online;' from user_indexes;

alter index indx_name rebuild  partition  indx_part_name tablespace tablespace_name;

select 'alter index '||owner||'.'||segment_name||' rebuild tablespace tabspace_name online nologging;'

from  dba_segments where tablespace_name =『tabspace_name』 and segment_type='index'

四、指定使用者預設的表空間

alter user "user_name"  default tablespace "test_spc";

五、如果刪除表空間之前刪除了表空間檔案,解決方法(oracle9i驗證通過):

$ sqlplus /nolog

sql> conn / as sysdba;

sql> shutdown abort

sql> startup mount

sql> alter datebase datafile 'datafilename' offine drop;

sql> alter database open;

sql> drop tablespace tablespace_name including contents;

六、在表空間聯機狀態下使該錶空間下的資料檔案離線後,在想把離線的資料檔案聯機就會報錯。可以直接離線表空間,該空間下的資料檔案也變成離線狀態。

七、分割槽表操作

--增加分割槽表

alter table bill_monthfee_zero add partition p_200409

values less than (200409) tablespace ts_ziken;

--刪除一分割槽

alter table part_tbl drop partition part_tbl_08;

--將乙個分割槽分為兩個分割槽

alter table bill_monthfee_zero split partition p_200409 at (200409)

into (partition p_200409_1 tablespace ts_ziken,

partition p_200409_2 tablespace ts_ziken_idx);

--合併分割槽

altertablebill_monthfee_zero

mergepartitions p_200408

,p_200409intopartitionp_all

--將分割槽改名

altertablebill_monthfee_zero renamepartitionp_200408top_fee_200408

--將分割槽改表空間

altertablebill_monthfee_zero movepartitionp_200409

tablespace ts_ziken_01 nologging

--查詢特定分割槽

select count(*) from bill_monthfee_zero partition (p_200407);

--新增資料

insert into bill_monthfee_zero select * from bill_monthfee_zero partition (p_200407)

--分割槽表的匯出

userid=dxsq/teledoone@jndxsq154

buffer=102400

tables=bill_monthfee:p_200401,

file=e:/exp_para/exp_dxsq_tables.dmp

log=e:/exp_para/exp_dxsq_tables.log

索引分割槽分為:本地(區域性)索引(local index) 全域性索引(global index)

一 本地索引

1.普通索引

sql > create index index_name on table (column)

local

(partition part_idx_01 tablespace index_space01,

partition part_idx_02 tablespace index_space02,

partition part_idx_03 tablespace index_space03

)2.唯一索引 如:主鍵

sql > create

unique

index index_name on table (column)

local

(partition part_idx_01 tablespace index_space01,

partition part_idx_02 tablespace index_space02,

partition part_idx_03 tablespace index_space03

)注:主鍵索引和主鍵約束的建立與刪除順序

建立主鍵索引 --> 建立主鍵約束

刪除主鍵約束 --> 刪除主鍵索引

3.非表分割槽字段唯一索引 表分割槽字段:usrid

sql > create

unique

index index_name on table (column,usrid)

local

(partition part_idx_01 tablespace index_space01,

partition part_idx_02 tablespace index_space02,

partition part_idx_03 tablespace index_space03

)二 全域性索引

1.範圍索引

sql > create [unique]index index_name on table(column)

global partition by range(column)

(partition part_idx_01 value less than(first range value) tablespace index_space01,

partition part_idx_02 value less than(second range value) tablespace index_space02,

partition part_idx_03 value less than(maxvalue) tablespace index_space03

)2.雜湊索引

sql > create [unique]index index_name on table(column,[column2])

global partition by hash(column,[column2])

(partition part_idx_01 tablespace index_space01,

partition part_idx_02 tablespace index_space02,

partition part_idx_03 tablespace index_space03)注:

1.分割槽字段不是主鍵的情況下,只可以建立全域性分割槽索引,不可以建立本地主鍵分割槽索引.

只有分割槽字段為主鍵時才可以建立本地主鍵分割槽索引.

2.如果建立本地唯一分割槽索引,除指定索引欄位外還要加上表分割槽欄位.

這種索引意義不大:因為這樣構成復合索引,索引改變,約束也改變了.

3.如果建立非唯一索引則不需要表分割槽欄位.

4.建立全域性分割槽索引後可以建立約束.

dba檢視索引分割槽

select * from dba_ind_partitions

user檢視索引分割槽

select * from user_ind_partitions

dba檢視索引分割槽型別

select * from dba_part_indexes

user檢視索引分割槽型別

select * from user_part_indexes

如何轉移表空間儲存位置

oracle安裝到了c盤,表空間也建立到了c盤,目前發現c盤的空間不夠用了,現在將表空間的檔案轉移到乙個容量大的盤下邊,操作方法 1.先登入sqlplus sqlplus nolog conn user1 passwd test 2.修改表空間為offline alter tablespace us...

轉移LOB欄位的表空間

部署時若要匯入的表空間名稱和開發機上的不一致,而你的表中有lob欄位,那頭就大了。能治好這種頭大症的 如下 create or replace procedure volumechangetableandindex tablespacename in varchar2 as cursor table...

Oracle 10g表轉移表空間

1.單錶轉移表空間 場景 有表user存放在表空間oldspace下,需把錶user移動到表空間newspace下 執行語句 alter table user move tablespace newspace commit 2.使用者scott下的所有表都轉移至表空間newspace下 select...