刪除Oracle某資料庫下的所有表

來源:互聯網
上載者:User

今天使用imp匯入dmp格式的Database Backup的時候,發現匯入出錯,提醒對象已經存在,才記起來要先刪除所有表才能匯入,如果資料庫有幾十上百個表的話,一個一個去刪除真浪費時間。為了方便,就寫了一條語句來查詢所有表和產生大量刪除的語句:

select 'drop table '||table_name||';' as sqlscript from user_tables;

SQLSCRIPT
--------------------------------------------
drop table LO_CASEINFO;
drop table LO_HARMONIZECASE;
drop table LO_LAWCHECK;
drop table LO_LEGISLATIONITEM;
drop table LO_TRAINBATCH;
drop table OA_IMPRESS;
drop table OA_SYSGROUP;

就可以複製所有表的drop語句了,一次批量執行完。

還有另外一個方法imp時使用ignore參數,可以忽略已經存在的對象,免除手動刪除表的操作:

參數說明:

Oracle在恢複資料的過程中,當恢複某個表時,該表已經存在,就要根據ignore參數的設定來決定如何操作。

若ignore=y,Oracle不執行CREATE TABLE語句,直接將資料插入到表中,假如插入的記錄違反了約束條件,比如主鍵約束,則出錯的記錄不會插入,但合法的記錄會添加到表中。

若ignore=n,Oracle不執行CREATE TABLE語句,同時也不會將資料插入到表中,而是忽略該表的錯誤,繼續恢複下一個表。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.