oracle 表空間

  • 創建表空間
    --查看所有用戶,以及對應的永久表空間,臨時表空間
    select username,default_tablespace,temporary_tablespace from dba_users

    where username='SYSTEM';


    1.1 創建臨時表空間
        CREATE TEMPORARY TABLESPACE DB_TEMP

             TEMPFILE 'D:appAdministratororadataNewDBDB_TEMP.DBF'

             SIZE 32M

             AUTOEXTEND ON

             NEXT 32M MASIZE UNLIMITED

             EXTENT MANAGEMENT LOCAL;



    1.2 創建數據表空間
        
        create tablespace 表空間名  
            datafile ' 路徑(要先建好路徑)\***.dbf  ' size *M  
                   ( ' 路徑\***.dbf ' size *M  )--這裏可以創建多個dbf文件
            autoextend on    --自動增長  
        next 5M          --增長梯度
        maxsize 3000M;   --最大範圍
            --還有一些定義大小的命令,看需要  
             default storage(  
             initial 100K,  
             next 100k,  
            );  


    ----非自動增長的表空間進行擴展

    alter tablespace <tablespace_name> add datafile '<file>' size <size> autoextend off;



    第三步:創建用戶並制定表空間
        CREATE USER NEWUSER IDENTIFIED BY BD123

             ACCOUNT UNLOCK

             DEFAULT TABLESPACE DB_DATA

             TEMPORARY TABLESPACE DB_TEMP;



    第四步:給用戶授予權限


    SQL> GRANT CONNECT,RESOURCE TO NEWUSER;  --表示把 connect,resource權限授予news用戶

    SQL> GRANT DBA TO NEWUSER;  --表示把 dba權限授予給NEWUSER用戶

        授權成功。

        OK! 數據庫用戶創建完成,現在你就可以使用該用戶創建數據表了!



    --案例:
    create tablespace mytest datafile '/home/oracle/dbdates/mytest.dbf' SIZE 20M;

    --創建用戶
    create user zzg identified by zzg123;

    --創建用戶並指定表空間
    create user demo identified by demo  default tablespace std;

    --修改用戶的表空間,到指定的表空間
    ALTER user ewell DEFAULT tablespace mytest;

    --刪除表空間(臨時表空間)
    drop tablespace mytest;刪除後dbf文件還在,可以通過下面語句找回
    (create tablespace name datafile '刪除表空間dbf路徑';)
    drop tablespace mytest including contents;刪除表空間和段,dbf文件還在

    drop tablespace mytest including contents and datafiles;將刪除表空間和段以及數據文件

    --修改用戶的密碼.
    alter user zzg identified by unis;

    --用戶授權
    grant create session to 用戶名;  

    ---查看當前用戶的所有權限
    select *from session_privs;


    --刪除用戶以及相關對象

    語法:drop user 用戶名;

    例子:drop user test;

    若用戶擁有對象,則不能直接刪除,否則將返回一個錯誤值。指定關鍵字cascade,可刪除用戶所有的對象,然後再刪除用戶。

    語法:
    drop user 用戶名 cascade;

    例子:drop user test cascade;


  • 發表評論
    所有評論
    還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
    相關文章