oracle建用户、授权、表空间语法及举例

一、建用户、表空间、授权

1.首先,创建(新)用户:
    create user username identified by password;
    username:新用户名的用户名
    password: 新用户的密码
也可以不创建新用户,而仍然用以前的用户,如:继续利用scott用户

2.创建表空间:
    create tablespace tablespacename datafile 'd:\data.dbf' size xxxm;
    tablespacename:表空间的名字
    d:\data.dbf':表空间的存储位置
    xxx表空间的大小,m单位为兆(M)
3.将空间分配给用户:
   alter user username default tablespace tablespacename;
   将名字为tablespacename的表空间分配给username 

4.给用户授权:
   grant create session,create table,unlimited tablespace to username;

5.然后再以楼主自己创建的用户登录,登录之后创建表即可。
   conn username/password;

6.查看服务名

   env |grep SID 

7.授予dba权限

   grant dba to username

8.使用上面的用户名、密码、sid登录plsql

二、删除表空间、用户

1.删除USER。

扫描二维码关注公众号,回复: 11842470 查看本文章

DROP USER XX CASCADE

2.删除表空间

DROP TABLESPACE tablespace_name INCLUDING CONTENTS AND DATAFILES;

3.删除空的表空间,不包含物理文件。

DROP TABLESPACE tablespace_name;

4.删除非空表空间,但是不包含物理文件

drop tablespace tablespace_name including contents;

5.删除空表空间,包含物理文件

drop tablespace tablespace_name including datafiles;

6.删除非空表空间,包含物理文件

drop tablespace tablespace_name including contents and datafiles;

7.如果其他表空间中的表有外键等约束关联到了本表空间中的表的字段,就要加上CASCADE CONSTRAINTS


drop tablespace tablespace_name including contents and datafiles CASCADE CONSTRAINTS;

拓展:

授权语句:

grant connect, resource, dba to user with admin option;

(注意:其中的“with admin option”选项的含义是权限转授,该用户user能把他得到的这个权限再转授给其他用户user。) 

经过授权以后,用户拥有connectresourcedba三个角色的权限:

Connect 角色

是授予最终用户的典型权利,最基本的权利,能够连接到ORACLE数据库中,并在对其他用户的表有访问权限时,做SELECT、UPDATE、INSERTT等操作。

Alter session--修改会话;

Create cluster--建立聚簇;

Create database link--建立数据库连接;

Create sequence--建立序列;

Create session--建立会话;

Create synonym--建立同义词;

Create view--建立视图。 

Resoure角色

是授予开发人员的,能在自己的方案中创建表、序列、视图等。

Create cluster--建立聚簇;

Create procedure--建立过程;

Create sequence—建立序列;

Create table--建表;

Create trigger--建立促发器;

Create type--建立类型。

DBA角色

是授予系统管理员的,拥有该角色的用户就能成为系统管理员了,它拥有所有的系统权限。

猜你喜欢

转载自blog.csdn.net/chudelong1/article/details/108897349