Oracle中快速刪除所有表資料

2021-10-23 20:32:02 字數 1218 閱讀 6834

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

在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 中快速刪除某個使用者下所有表資料

一 禁止所有的外來鍵約束 在pl sql developer下執行如下語句 select alter table table name disable constraint constraint name from user constraints where constraint type r 把...

Oracle刪除所有表

oracle刪除所有表,最好的方式是刪除乙個使用者及下面的所有表.所以,最好在插入資料建立表結構的時候,建立乙個新的使用者,而不是使用system帳戶 建立使用者的語句 新增使用者 11g可以使用system pwd as sysdba 來以管理員身份登入進去 建立c scott 使用者 oracl...

oracle刪除所有表

select drop table table name from user tables order by table name 執行查詢結果執行即可刪除所有表。刪除後的表並沒有徹底刪除,還會生成bin 開頭的表,在 站可以徹底刪除或還原。select drop table table name ...