管理用戶
一、默認臨時和永久表空間
可以在數據庫指定默認的臨時表空間和默認的永久表空間,這樣在沒有爲用戶指定默認臨時表空間和默認永久表空間時,使用它們作爲用戶的默認臨時表空間和默認永久表空間。當然也可以在創建用戶時指定它們或者創建用戶之後更改它們。
更改數據庫默認臨時表空間和默認永久表空間:
alter database default tablespace tbs_name;
alter database default temporary tablespace temp_tbs_name;
查詢數據庫的默認臨時表空間和默認永久表空間
select property_value from database_properties
where property_name='DEFAULT_PERMANENT_TABLESPACE';
select property_value from database_properties
where property_name='DEFAULT_TEMP_TABLESPACE';
二、創建用戶
create user user_name identified by password --這裏僅說明用戶使用數據庫驗證,至於其他的驗證方法以後再寫。
[default tablespace tbs_name] --指定用戶默認永久表空間
[temporary tablespace temp_tbs_name] --指定用戶默認臨時表空間
[quota {nm |unlimited} on tablespace_name] --指定用戶在某個表空間上的配額,unlimited爲不受限制,可以使用表空間所有可用空間。
[quota ...
...] --可以使用quota指定用戶在多個表空間上配額
[profile profile_name] --指定用戶的概要文件
[password expire] --指定用戶的初始密碼是否過期
[account {unlock | lock}] --指定用戶是否鎖定
也可以在爲用戶分配權限時創建用戶,比如:grant create session to user_name identified by password;
創建用戶之後仍然不能登錄數據庫,至少需要create session權限:grant create session to user_name;
如果不想讓用戶在數據庫上進行任何操作而不想刪除用戶模式下的對象,可以收回create session權限:revoke create session from user_name;
新創建的用戶要想創建不僅需要相應的權限,而且需要在表空間上的配額:alter user user_name {quota nm | unlimited} on tablespace_name;
如果不想讓用戶創建任何對象,其中一個辦法是更改用戶在所有表空間上的配額爲0:alter user user_name quota 0 on tablespace_name;
當用戶在表空間沒有配額時,用戶的原有對象唄保留,但不能增大,也不能創建新對象。
用戶具有unlimited tablespace權限,就可以使用任何表空間的可用空間:grant unlimited tablespace to user_name;
用戶在自己創建的表空間上可以使用任何可用空間。
使用user_ts_quotas查詢用戶的在表空間上配額。
三、更改用戶
使用alter user完成下列工作
1、更改用戶密碼:alter user user_name identified by new_password;
在sql*plus上也可以使用password修改用戶密碼:a、修改自己用戶密碼 sql>password --要求提供原密碼
b、修改其他用戶密碼sql>password user_name --要求具有alter user權限,不要求提供user_name用戶的原密碼。
2、更改用戶的默認表空間:alter user user_name default tablespace tablespace_name;
3、更改用戶的默認臨時表空間:alter user user_name temporary tablespace tem_tbs_name;
4、更改用戶在表空間上的配額:alter user user_name quota {nm | unlimited} on tablespace_name
5、更改用戶的概要文件:alter user user_name profile profile_name
6、鎖定/解鎖用戶:alter user user_name account {lock | unlock};
7、使用戶密碼過期:alter user user_name password expire;
8、更改用戶默認角色:alter user user_name default role role_name;
四、刪除用戶
1、刪除用戶:用戶沒有對象 drop user user_name;
2、刪除用戶:用戶有對象:drop user user_name cascade;
如果用戶有對象,而不確定這些對象是否還有用,可以先不刪除,而是收回create session權限。
如果刪除用戶,其對象不會進入回收站,而是直接刪除。