Oracle創(chuàng)建/刪除、導入/導出等命令總結(jié)

字號:


    //創(chuàng)建臨時表空間
    create temporary tablespace zfmi_temp
    tempfile 'D:oracleoradatazfmizfmi_temp.dbf'
    size 32m
    autoextend on
    next 32m maxsize 2048m
    extent management local;
    //tempfile參數(shù)必須有
    //創(chuàng)建數(shù)據(jù)表空間
    create tablespace zfmi
    logging
    datafile 'D:oracleoradatazfmizfmi.dbf'
    size 100m
    autoextend on
    next 32m maxsize 2048m
    extent management local;
    //datafile參數(shù)必須有
    //刪除用戶以及用戶所有的對象
    drop user zfmi cascade;
    //cascade參數(shù)是級聯(lián)刪除該用戶所有對象,經(jīng)常遇到如用戶有對象而未加此參數(shù)則用戶刪不了的問題,所以習慣性的加此參數(shù)
    //刪除表空間
    前提:刪除表空間之前要確認該表空間沒有被其他用戶使用之后再做刪除
    drop tablespace zfmi including contents and datafiles cascade onstraints;
    //including contents 刪除表空間中的內(nèi)容,如果刪除表空間之前表空間中有內(nèi)容,而未加此參數(shù),表空間刪不掉,所以習慣性的加此參數(shù)
    //including datafiles 刪除表空間中的數(shù)據(jù)文件
    //cascade constraints 同時刪除tablespace中表的外鍵參照
    如果刪除表空間之前刪除了表空間文件,解決辦法:
    如果在清除表空間之前,先刪除了表空間對應的數(shù)據(jù)文件,會造成數(shù)據(jù)庫無法正常啟動和關(guān)閉。
    可使用如下方法恢復(此方法已經(jīng)在oracle9i中驗證通過):
    下面的過程中,filename是已經(jīng)被刪除的數(shù)據(jù)文件,如果有多個,則需要多次執(zhí)行;tablespace_name是相應的表空間的名稱。
    $ sqlplus /nolog
    SQL> conn / as sysdba;
    如果數(shù)據(jù)庫已經(jīng)啟動,則需要先執(zhí)行下面這行:
    SQL> shutdown abort
    SQL> startup mount
    SQL> alter database datafile 'filename' offline drop;
    SQL> alter database open;
    SQL> drop tablespace tablespace_name including contents;
    //創(chuàng)建用戶并指定表空間
    create user zfmi identified by zfmi
    default tablespace zfmi temporary tablespace zfmi_temp;
    //identified by 參數(shù)必須有
    //授予message用戶DBA角色的所有權(quán)限
    GRANT DBA TO zfmi;
    //給用戶授予權(quán)限