Linux 下创建oracle表空间和用户 及 删除表空间

转载:http://kingxss.iteye.com/blog/1741076

创建用户和表空间: 


1、登录linux,以oracle用户登录(如果是root用户登录的,登录后用 su - oracle命令切换成oracle用户)

2、以sysdba方式来打开sqlplus,命令如下: sqlplus / as sysdba

3、创建临时表空间:
Sql代码   收藏代码
  1. --查询临时表空间文件的绝对路径。如果需要的话,可以通过查询来写定绝对路径。一般用${ORACLE_HOME}就可以了  
  2. select name from v$tempfile;  
  3. create temporary tablespace NOTIFYDB_TEMP tempfile '${ORACLE_HOME}\oradata\NOTIFYDB_TEMP.bdf' size 100m reuse autoextend on next 20m maxsize unlimited;  

 

4、创建表空间:

Sql代码   收藏代码
  1. --查询用户表空间文件的绝对路径:  
  2. select name from v$datafile;  
  3. create tablespace NOTIFYDB datafile '${ORACLE_HOME}\oradata\notifydb.dbf' size 100M reuse autoextend on next 40M maxsize unlimited default storage(initial 128k next 128k minextents 2 maxextents unlimited);  

 

5、创建用户和密码,指定上边创建的临时表空间和表空间

Sql代码   收藏代码
  1. create user hc_notify identified by hc_password default tablespace NOTIFYDB temporary tablespace NOTIFYDB_TEMP;  

 

6、赋予权限

Sql代码   收藏代码
  1. grant dba to hc_notify;  
  2. grant connect,resource to hc_notify;  
  3. grant select any table to hc_notify;  
  4. grant delete any table to hc_notify;  
  5. grant update any table to hc_notify;  
  6. grant insert any table to hc_notify;  

 

经过以上操作,就可以使用hc_notify/hc_password登录指定的实例,创建我们自己的表了。


删除表空间:

1、查看用户权限

Sql代码   收藏代码
  1. --查看用户要具备drop tablespace的权限,如果没有,先用更高级的用户(如sys)给予授权  
  2. select a2.username,a1.privilege from dba_sys_privs a1 , user_role_privs a2  
  3. where a1.privilege = 'DROP TABLESPACE'  
  4. and a1.grantee =a2.granted_role  

 

2、删除临时表空间

Sql代码   收藏代码
  1. --查看临时表空间文件  
  2. select name from v$tempfile;  
  3. --查看用户和表空间的关系  
  4. select USERNAME,TEMPORARY_TABLESPACE from DBA_USERS;  
  5. --如果有用户的默认临时表空间是NOTIFYDB_TEMP的话,建议进行更改  
  6. alter user xxx temporary tablespace tempdefault;  
  7. ---设置tempdefault为默认临时表空间  
  8. alter database default temporary tablespace tempdefault;  
  9. --删除表空间NOTIFYDB_TEMP及其包含数据对象以及数据文件  
  10. drop tablespace NOTIFYDB_TEMP including contents and datafiles;   

 

3.删除用户表空间

Sql代码   收藏代码
  1. --查看表空间文件  
  2. select name from v$datafile;  
  3. --停止表空间的在线使用  
  4. alter tablespace 表空间名称 offline;  
  5. --删除表空间NOTIFYDB_TEMP及其包含数据对象以及数据文件  
  6. drop tablespace NOTIFYDB including contents and datafiles;   
  7. 语法:
  8. DROP TABLESPACE tablespace_name  [ including contents [ and datafiles ] [ CASCADE CONSTRAINT ] ];
       无选项 -- 当表空间为空才能删除;
       including contents — 删除表空间及对象;
       including contents and datafiles — 删除表空间、对象及数据文件;
       includingcontents CASCADE CONSTRAINT — 删除关联;
       including contents and datafiles cascade constraint -- 含前两项。

 

Oracle用户权限查询相关操作:

Sql代码   收藏代码
  1. --查看所有的用户  
  2. select * from all_users;  
  3. --查看当前用户信息  
  4. select * from user_users;  
  5. --查看当前用户的角色  
  6. select * from user_role_privs;  
  7. --查看当前用户的权限  
  8. select * from user_sys_privs;  
  9. --查看当前用户的表可操作权限  
  10. select * from user_tab_privs;  
  11.   
  12. --查看某一个表的约束,注意表名要 大写  
  13. select * from user_constraints where table_name='TBL_XXX';  
  14. --查看某一个表的所有索引,注意表名要 大写  
  15. select index_name,index_type,status,blevel from user_indexes where table_name = 'TBL_XXX';  
  16. --查看索引的构成,注意表名要 大写  
  17. select table_name,index_name,column_name, column_position FROM user_ind_columns WHERE table_name='TBL_XXX';  
  18.   
  19. --系统数据字典 DBA_TABLESPACES 中记录了关于表空间的详细信息  
  20. select * from sys.dba_tablespaces;  
  21.   
  22. --查看用户序列  
  23. select * from user_sequences;  
  24. --查看数据库序列  
  25. select * from dba_sequences;  

猜你喜欢

转载自blog.csdn.net/chuan_zhang_ak/article/details/80793847