Oracle表空间与权限管理

---------------------创建用户表空间---------------------------------
-- 创建永久表空间的语法:
/*
   create tablespace 表空间名称 
          datafile 表空间物理文件存储的路径 
          size 表空间大小(以兆为单位)
          <autoextend on>
    临时表空间
    create temporary tablespace 表空间名称
           tempfile 文件存储路径
           size 表空间大小   
*/


create tablespace test_space datafile 'E:\gerry\space\test.dbf' size 10m;
create temporary tablespace temp_space tempfile 'E:\gerry\space\test_temp.dbf'
       size 2M;


/*
   修改表空间大小
*/
alter database datafile 'E:\gerry\space\test.dbf' resize 2m;
/*
   增加表空间    
*/
alter tablespace test_space 
      add datafile 'E:\gerry\space\test_1.dbf' size 2m;
      
-- 查询当前用户所有表空间管理物理文件
select tablespace_name,file_name from dba_data_files;


-- 删除表空间
drop tablespace test_space including contents; -- 推荐
drop tablespace test_space including contents and datafiles; -- 不推荐
drop tablespace temp_space including contents and datafiles; -- 推荐


-- 删除用户表空间的时候必须把默认改为users
alter user gerry default tablespace users;


-----------
/*
一个表空间则对应着一个或多个物理的数据库文件
但是一个物理文件只能对应一个表空间
*/


---------------------数据库安全管理---------------------------------
-- 创建用户
-- 语法: create user 账号名称 identified by 密码(必须字母和数字组成)
--       <default tablespace 表空间名称>
create user gerry identified by 123 default tablespace test_space;
-- 授权
-- 语法: grant 权限/角色名称 to 账号名称
grant create session to gerry; -- 授予登录的权限
grant unlimited tablespace to gerry; -- 授予操作表空间的权限
grant create table to gerry; -- 授予创建表的权限
grant select on scott.emp to gerry; -- 授予用户查询scott的emp表的权限


-- 撤销权限
-- 语法:revoke 权限/角色名称 from 账号名称
revoke create session from gerry;
revoke unlimited tablespace from gerry;
revoke create table from gerry;
revoke select on scott.emp from gerry;




-- 授予用户角色
-- connect,resource,dba
grant connect,resource to gerry;
revoke connect,resource from gerry;


-- 自定义系统角色
-- 创建一个角色
create role myRole;
-- 给角色授权
grant connect to myRole;
grant resource to myRole;
grant select any table to myRole;
grant unlimited tablespace to myRole;


-- 给gerry授权自定义角色
grant myRole to gerry;
revoke myRole from gerry;


-- 删除角色
drop role myRole;
-- 删除用户
drop user gerry cascade;



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值