oracle 中快速刪除某個使用者下所有表資料

2021-09-08 06:12:43 字數 1218 閱讀 8271

一、禁止所有的外來鍵約束

在pl/sql developer下執行如下語句:

select 'alter table ' || table_name || ' disable constraint ' || constraint_name || ';' from user_constraints where constraint_type = 'r';

把查詢出來的結果拷出來在pl/sql developer時執行。

若沒有pl/sql developer,可以在sqlplus裡操作,方法如下:

1. 開啟sqlplus,並用相應的使用者連線。

2. 把pagesize設大點,如set pagesize 20000

3. 用spool把相應的結果導到檔案時,如

sql> spool /home/oracle/constraint.sql

sql> select 'alter table ' || table_name || ' disable constraint ' || constraint_name || ';' from user_constraints where constraint_type = 'r';

sql> spool off

4. 已經生成了包含相應語句的指令碼,不過指令碼檔案裡的最前和最後面有多餘的語句,用文字編輯器開啟,並刪除沒用的語句即可

5. 重新用相應的使用者登入sqlplus,執行如下命令

sql> @/home/oracle/constraint.sql

二、用delete或truncate刪除所有表的內容

select 'delete from '|| table_name || ';' from user_tables

order by table_name;

或select 'truncate table '|| table_name || ';' from user_tables

order by table_name;

用第一步類似的方法操作。要注意的一點是,若表的資料有觸發器相關聯,只能用truncate語句,不過truncate語句不能回滾,所以時要注意

三、把已經禁止的外來鍵開啟

select 'alter table ' || table_name || ' enable constraint ' || constraint_name || ';' from user_constraints where constraint_type = 'r';

oracle刪除某個使用者所有表

1 select drop table table name from all tables where owner 要刪除的使用者名稱 注意要大寫 2 刪除所有表 以使用者test為例 for example declare cursor cur1 is select table name fro...

Oracle中刪除某個使用者下的所有表

一般的方法 先使用sql查詢 select delete from table name from user tables order by table name 將查詢結果複製一下,在sql命令視窗裡再執行一次就刪除了所有的表。select drop table table name from c...

oracle 刪除某個使用者下的所有物件

先存放好dropobj.sql 檔案 然後登入需要刪除的使用者 刪除前最好備份一下 備份是在cmd中進行的 c users panfu exp file d expall.dmp log expall.logfull y export release 10.2.0.1.0 production on...