oracle创建新用户,并把表放到新的表空间上

概要:由于要新起一个项目,想的是数据库独立,包括以后数据方便迁移。因此决定在公司现有的数据库(oracle)基础上 新建一个用户,并把表放在一个新的表空间里

环境:oracle11g 

当前数据库实例为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/

猜你喜欢

转载自www.cnblogs.com/wangted007/p/9502463.html