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

字號(hào):


    //創(chuàng)建臨時(shí)表空間
    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ù)必須有
    //刪除用戶以及用戶所有的對(duì)象
    drop user zfmi cascade;
    //cascade參數(shù)是級(jí)聯(lián)刪除該用戶所有對(duì)象,經(jīng)常遇到如用戶有對(duì)象而未加此參數(shù)則用戶刪不了的問題,所以習(xí)慣性的加此參數(shù)
    //刪除表空間
    前提:刪除表空間之前要確認(rèn)該表空間沒有被其他用戶使用之后再做刪除
    drop tablespace zfmi including contents and datafiles cascade onstraints;
    //including contents 刪除表空間中的內(nèi)容,如果刪除表空間之前表空間中有內(nèi)容,而未加此參數(shù),表空間刪不掉,所以習(xí)慣性的加此參數(shù)
    //including datafiles 刪除表空間中的數(shù)據(jù)文件
    //cascade constraints 同時(shí)刪除tablespace中表的外鍵參照
    如果刪除表空間之前刪除了表空間文件,解決辦法:
    如果在清除表空間之前,先刪除了表空間對(duì)應(yīng)的數(shù)據(jù)文件,會(huì)造成數(shù)據(jù)庫(kù)無法正常啟動(dòng)和關(guān)閉。
    可使用如下方法恢復(fù)(此方法已經(jīng)在oracle9i中驗(yàn)證通過):
    下面的過程中,filename是已經(jīng)被刪除的數(shù)據(jù)文件,如果有多個(gè),則需要多次執(zhí)行;tablespace_name是相應(yīng)的表空間的名稱。
    $ sqlplus /nolog
    SQL> conn / as sysdba;
    如果數(shù)據(jù)庫(kù)已經(jīng)啟動(dò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)限