Oracle學習(二)使用者和表空間詳解

2021-09-13 16:09:48 字數 2982 閱讀 6824

使用者登入格式:[username/password] [@server] [as sysdba|sysoper]

如果已經使用某個使用者登入了sql plus,切換登入使用者:

connect sys/口令as sysdba

備註:書寫不區分大小寫!

① show user命令,不需要加分號,當是輸入的是sql語句時,需要加分號;

② dba_users資料字典, 資料庫提供的表,也是由很多的字段組成。

③ desc dba_users可以檢視資料字典中的字段

select username from daba_users;
alter user username account unlock(解鎖/lock上鎖)
connect scott/tiger
資料庫的邏輯儲存空間,可以理解為在資料庫中開闢的空間用來儲存資料庫物件;

表空間由乙個或多個資料檔案組成;資料檔案的大小和位置可以自己定義;

① 永久表空間:資料庫中要永久化儲存的一些物件,如:表、檢視、儲存過程。

② 臨時表空間:資料庫操作當中中間執行的過程,執行結束後,存放的內容會被自動釋放。

③ undo表空間:用於儲存事務所修改資料的舊值,可以進行資料的回滾。

許可權大的可以檢視許可權小的,反之不行。

① dba_tablespaces(系統管理員級別檢視)

② user_tablespaces資料字典(普通使用者檢視)

desc dba_tablespaces
select tablespace_name from dba_tablespace;
備註:普通使用者級別的檢視操作同上

desc dba_users
備註:每乙個使用者下面可以對應著預設表空間和臨時表空間,預設表空間,就是在這個使用者下建立物件所存在的位置,臨時表空間,就是存放的是臨時資訊,通常情況下就只有乙個臨時表空間

select default_tablespace,temporary_tablespace from dba_users where username =』system』;
結果如下圖 :

altem user username(需要更改的表空間名字)

default(預設)|temporary(臨時) tablespace tablespace_name(更改後的名字)

select default_tablespace,temporary_tablespace from dba_users where username='';

備註:通過select來檢視修改之後的表空間。

測試如下圖:

create [temporary(建立臨時表空間需要加上)] tablespace tablespace_name

tempfile|datefile 『xx.dbf』 size(資料檔案的大小 ) xx

desc dba_data_files

select file_name from dba_data_files where tablespace_name=」;(條件是表空間的名字,需要大寫)

測試如下圖:

設定聯機或離線狀態(表空間預設是聯機的,離線狀態不可用)

alter tablespace tablespace_name

online|offline;

檢視表空間所處的狀態(通過dba_tablespaces資料字典),可通過檢視資料字典中的status,來判斷狀態。

desc dba_tablespaces

select status from dba_tablespaces where tablespace_name=」;(條件是表空間的名字,需要大寫)

alter tablespace tablespace_name

read only|read write

alter tablespace tablespace_name

add datatfile 『xx.dbf』 size xx;

通過select語句查詢到當前表空間中的資料檔案

select file_name from dba_data_files where tablespace_name=」;(條件是表空間的名字,需要大寫)
alter tablespace tablespace_name

drop datatfile 『xx.dbf』 size xx;

drop tablespace tablespace_name[including contents]
如果只是刪除表空間不刪除該錶空間下的資料檔案,則不加include contents;

例如:刪除已經建立的表空間

oracle學習筆記二 使用者管理

在用oracle的時候,跟以前所用的sql server感覺有比較大的差別,在oracle中,使用者是乙個很關鍵,並且很有味道的東西。oracle在大型資料庫中排行老二,最大型的資料庫是db2,第三是sybase,雖然說它只是第二大型資料庫,但是它是佔市場份額最大的一種資料庫,這裡就不討論各種大型資...

oracle使用者和表空間

建立表空間 create tablespace test1 table datafile test1file.dbf size 10m 建立永久表空間 create temporary tablespace temptest1 tablespace tempfile test1tempfile.db...

Oracle建立表空間和使用者

oracle建立表空間和使用者 sql view plain copy 建立表空間和使用者的步驟 使用者 建立 create user 使用者名稱 identified by 密碼 授權 grant create session to 使用者名稱 grant create table to 使用者名...