Oracle中關於清除數據和釋放表空間

1、表的重命名linux

flashback table test2 to before drop rename to test3;--【to test3】將表重命名sql

drop table test3 purge; --完全刪除表oop


2、清除表中的數據網站

truncate操做 同沒有where條件的delete操做十分類似,只是把表裏的信息所有刪除,可是表依然存在。spa

例如:truncate table  XXhtm

Truncate不支持回滾,而且不能truncate一個帶有外鍵的表,若是要刪除首先要取消外鍵,而後再刪除。blog

truncate table 後,有可能表空間仍沒有釋放,可使用以下語句:get

alter table 表名稱 deallocate   UNUSED KEEP 0;flash

注意若是不加KEEP 0的話,表空間是不會釋放的。it

例如:

alter table F_MINUTE_TD_NET_FHO_B7 deallocate   UNUSED KEEP 0;

或者:

TRUNCATE TABLE (schema)table_name DROP(REUSE) STORAGE才能釋放表空間。

例如: truncate table  test1 DROP STORAGE;

 

3、查詢分區表存在哪些分區:

查詢分區表的狀況,能夠在USER_TAB_PARTITIONS中查詢。例如:

    select 'alter table '||t.table_name ||' truncate   partition ' || t.partition_name from USER_TAB_PARTITIONS t where t.table_name like 'F_%'

    清除指定某個分區表的分區數據:

    alter   table  表名稱   truncate   partition   分區名稱;

4、清除分區表佔用的空間:

alter table 表名稱  DROP    partition 分區名稱;

    例如:

    alter table F_HOUR_TD_NET_MPVOICE  DROP    partition P_09121913;

5、查詢表空間信息

    能夠利用以下語句查詢各表在存儲空間的使用分狀況:

    SELECT  TABLESPACE_NAME,TO_CHAR(SUM(BYTES)/(1024*1024),'999G999D999')   CNT_MB   FROM   DBA_EXTENTS   WHERE   OWNER='&OWNER'   AND   SEGMENT_NAME='&TABLE_NAME'   AND   SEGMENT_TYPE   LIKE   'TABLE%'   GROUP   BY   TABLESPACE_NAME;

可使用以下語句,查詢存儲空間狀況:

Select Tablespace_Name, Sum(bytes)/1024/1024 From Dba_Segments group By Tablespace_Name

 

6、查詢用戶下的表

    若是你的用戶權限不是DBA:  

  那你用  

  select   *   from   user_tables;  

  能夠查詢到當前用戶所擁有的表。  

  若是是DBA用戶:  

  select   *   from   dba_tables;

 

7、刪除指定空間下的全部表

declare 
vsql varchar2(200);
cursor c1 is 
  select 'drop table '||table_name||' cascade constraints' v_name ,tablespace_name
   from user_tables where tablespace_name='$tablename';
    
  BEGIN
  for i in c1 loop
  vsql:=i.v_name;
  execute immediate vsql;
end loop;
end; 

 

 

本篇文章來源於 Linux公社網站(www.linuxidc.com)  原文連接:http://www.linuxidc.com/Linux/2010-12/30353p2.htm

相關文章
相關標籤/搜索