批量修改table和index 的表空間

由於開發人員把ess 項目下的大部分對象放到user 表空間中,用imp/exp 導入正式庫後,ess用戶的對象還是在users 表空間中.爲了把ESS 的對象放到ess 默認的表空間ess中,我按如下幾步操作:

 

  1 找出要修改表空間的對象:

 

  

    select * from dba_tables  where owner='ESS' and tablespace_name = 'USERS';

 

   

   select * from dba_INDEXES where table_owner='ESS' and tablespace_name = 'USERS';

 

2 . 生成批量修改的sql 語句

 

 

 select 'alter table ess.' || table_name || ' move tablespace ess;'
from dba_tables where owner='ESS' and tablespace_name = 'USERS';

 

 

select 'alter index ess.'||index_name||' rebuild online nologging tablespace ess;'
 from DBA_indexes
WHERE table_owner='ESS' and tablespace_name = 'USERS'

 

 

 

 

把生成sql 語句導到 到ess_table.txt和ess_index.txt 文件中

 

3. 執行 ess_table.txt 和 ess_index.txt 文件 sqll 語句 ,就OK

 

4  檢查users 表空間,看看ess 用戶的對象是不是少了


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章