//連接
connect /as sysdba
1.創建表空間和用戶并為用戶指定表空間
//創建臨時表空間
create temporary tablespace user_temp tempfile 'D:oracleoradatauser_temp.dbf' size 50m autoextend on next 50m maxsize 20480m extent management local;
(注:user_temp是臨時表空間的名稱。)
//創建數據表空間lportal
create tablespace lportal logging datafile 'D:oracleoradatalportal.dbf' size 100m autoextend on next 50m extent management local;
(注:lportal是數據表空間的名稱。)
//創建用戶lportal并指定表空間
create user lportal identified by lportal default tablespace lportal_db temporary tablespace user_temp;
(注:第一個lportal是用戶名,第二個lportal是密碼;lportal_db是數據表空間名稱,user_temp是臨時表空間名稱。)
//為lportal用戶授權
grant connect,resource,dba to lportal;
2.數據備份(導入導出數據)
//導入數據
imp lportal/lportal@orcl file=d:lportal20121109.dmp full=Y
//導出數據
exp lportal/lportal@orcl file=D:lportal20121109.dmp
(數據的導入與導出,在進入到黑窗口后直接輸入上列語句,不需要進入sqlplus)
3.刪除用戶及表空間
//刪除用戶以及用戶所有的對象
drop user lportal cascade;
//刪除表空間與表空間文件(注意:如果在創建表空間的時候帶有雙引號,則刪除的時候也要帶上)
DROP TABLESPACE "stu_new" INCLUDING CONTENTS AND DATAFILES;
前提:刪除表空間之前要確認該表空間沒有被其他用戶使用之后再做刪除
drop tablespace zfmi including contents and datafiles cascade onstraints;
//including contents 刪除表空間中的內容,如果刪除表空間之前表空間中有內容,而未加此參數,表空間刪不掉,所以習慣性的加此參數
//including datafiles 刪除表空間中的數據文件
//cascade constraints 同時刪除tablespace中表的外鍵參照
4.查詢表空間和查詢用戶
//查詢所有表空間名稱
select tablespace_name from dba_tablespaces;
//查看表空間的名稱和狀態
select tablespace_name,status from dba_tablespaces;
//查詢當前表空間屬性
select * from dba_tablespaces where tablespace_name='mtgyd';
//查詢所有用戶
select username from dba_users;