概要:由於要新起一個項目,想的是數據庫獨立,包括以后數據方便遷移。因此決定在公司現有的數據庫(oracle)基礎上 新建一個用戶,並把表放在一個新的表空間里
環境:oracle11g
首先需要以sysdba的角色登錄
sqlplus sys/password as sysdba
——其中password為密碼
然后開始添加用戶
當前數據庫實例為orcl;
擬新建的user為這里定義為newuser,密碼password;
表空間為newuser_tablespace
----------------------------------以下為正文-------------------------------------------------------------------------------------------------------------------
--創建用戶
create user newuser identified by password;
--創建表空間
create tablespace newuser_tablespace datafile '文件路徑\BONDRATING_DATA.DBF'
size 200m
autoextend on
next 32m maxsize 2048m
extent management local;
--創建臨時表空間
create temporary tablespace newuser_tablespace_TEMP tempfile '文件路徑\BONDRATING_TEMP.dbf' size 50M autoextend ON next 10M maxsize 100M;
--分配表空間和臨時表空間
alter user newuser default tablespace newuser_tablespace temporary tablespace newuser_tablespace_TEMP;
--給用戶分配權限
grant create session,create table,create view,create sequence,unlimited tablespace to newuser;
其他補充1:關於用戶和表空間的一些查詢
--查詢所有用戶
select * from dba_users;
--查看所有用戶所在表空間
select username,default_tablespace from dba_users;
--查詢所有表空間路徑
select * from dba_data_files ;
其他補充2:關於如何刪除表空間
--刪除空的表空間,但是不包含物理文件
drop tablespace tablespace_name;
--刪除非空表空間,但是不包含物理文件
drop tablespace tablespace_name including contents;
--刪除空表空間,包含物理文件
drop tablespace tablespace_name including datafiles;
--刪除非空表空間,包含物理文件
drop tablespace tablespace_name including contents and datafiles;
--如果其他表空間中的表有外鍵等約束關聯到了本表空間中的表的字段,就要加上CASCADE CONSTRAINTS
drop tablespace tablespace_name including contents and datafiles CASCADE CONSTRAINTS;
關於一些參考鏈接
https://www.cnblogs.com/paulen/p/paulen.html
http://blog.itpub.net/29612373/viewspace-2099197/