orcale 角色大全

一、权限分类:
系统权限:系统规定用户使用数据库的权限。(系统权限是对用户而言)。

实体权限:某种权限用户对其它用户的表或视图的存取权限。(是针对表或视图而言的)。



二、系统权限管理:
1、系统权限分类:
DBA: 拥有全部特权,是系统最高权限,只有DBA才可以创建数据库结构。

RESOURCE:拥有Resource权限的用户只可以创建实体,不可以创建数据库结构。

CONNECT:拥有Connect权限的用户只可以登录Oracle,不可以创建实体,不可以创建数据库结构。

对于普通用户:授予connect, resource权限。
对于DBA管理用户:授予connect,resource, dba权限。



2、系统权限授权命令:
[系统权限只能由DBA用户授出:sys, system(最开始只能是这两个用户)]
授权命令:SQL> grant connect, resource, dba to 用户名1 [,用户名2]...;

[普通用户通过授权可以具有与system相同的用户权限,但永远不能达到与sys用户相同的权限,system用户的权限也可以被回收。]

例:
SQL> connect system/manager
SQL> Create user user50 identified by user50;
SQL> grant connect, resource to user50;

查询用户拥有哪里权限:
SQL> select * from dba_role_privs;
SQL> select * from dba_sys_privs;
SQL> select * from role_sys_privs;

删除用户:SQL> drop user 用户名 cascade;  //加上cascade则将用户连同其创建的东西全部删除



3、系统权限传递:
增加WITH ADMIN OPTION选项,则得到的权限可以传递。

SQL> grant connect, resorce to user50 with admin option;  //可以传递所获权限。



4、系统权限回收:系统权限只能由DBA用户回收
命令:SQL> Revoke connect, resource from user50;



说明:

1)如果使用WITH ADMIN OPTION为某个用户授予系统权限,那么对于被这个用户授予相同权限的所有用户来说,取消该用户的系统权限并不会级联取消这些用户的相同权限。

2)系统权限无级联,即A授予B权限,B授予C权限,如果A收回B的权限,C的权限不受影响;系统权限可以跨用户回收,即A可以直接收回C用户的权限。



三、实体权限管理
1、实体权限分类:select, update, insert, alter, index, delete, all  //all包括所有权限
execute  //执行存储过程权限

user01:
SQL> grant select, update, insert on product to user02;
SQL> grant all on product to user02;

user02:
SQL> select * from user01.product;

// 此时user02查user_tables,不包括user01.product这个表,但如果查all_tables则可以查到,因为他可以访问。


2. 将表的操作权限授予全体用户:
SQL> grant all on product to public;  // public表示是所有的用户,这里的all权限不包括drop。

[实体权限数据字典]:
SQL> select owner, table_name from all_tables; // 用户可以查询的表
SQL> select table_name from user_tables;  // 用户创建的表
SQL> select grantor, table_schema, table_name, privilege from all_tab_privs; // 获权可以存取的表(被授权的)
SQL> select grantee, owner, table_name, privilege from user_tab_privs;   // 授出权限的表(授出的权限)



3. DBA用户可以操作全体用户的任意基表(无需授权,包括删除):
DBA用户:
SQL> Create table stud02.product(
id number(10),
name varchar2(20));
SQL> drop table stud02.emp;

SQL> create table stud02.employee
as
select * from scott.emp;

4. 实体权限传递(with grant option):
user01:

SQL> grant select, update on product to user02 with grant option; // user02得到权限,并可以传递。



5. 实体权限回收:
user01:
SQL>Revoke select, update on product from user02;  //传递的权限将全部丢失。



说明

1)如果取消某个用户的对象权限,那么对于这个用户使用WITH GRANT OPTION授予权限的用户来说,同样还会取消这些用户的相同权限,也就是说取消授权时级联的。





Oracle 用户管理
一、创建用户的Profile文件
SQL> create profile student limit  // student为资源文件名
FAILED_LOGIN_ATTEMPTS  3  //指定锁定用户的登录失败次数
PASSWORD_LOCK_TIME 5  //指定用户被锁定天数
PASSWORD_LIFE_TIME 30  //指定口令可用天数


二、创建用户
SQL> Create User username
Identified by password
Default Tablespace tablespace
Temporary Tablespace tablespace
Profile profile
Quota integer/unlimited on tablespace;

例:
SQL> Create user acc01
identified by acc01   // 如果密码是数字,请用双引号括起来
default tablespace account
temporary tablespace temp
profile default
quota 50m on account;
SQL> grant connect, resource to acc01;

查询用户缺省表空间、临时表空间 SQL> select username, default_tablespace, temporary_tablespace from dba_users;

查询系统资源文件名: SQL> select * from dba_profiles;
资源文件类似表,一旦创建就会保存在数据库中。
SQL> select username, profile, default_tablespace, temporary_tablespace from dba_users;

SQL> create profile common limit
failed_login_attempts 5
idle_time 5;

SQL> Alter user acc01 profile common;



三、修改用户:
SQL> Alter User 用户名
Identified 口令
Default Tablespace tablespace
Temporary Tablespace tablespace
Profile profile
Quota integer/unlimited on tablespace;

1、修改口令字:
SQL>Alter user acc01 identified by "12345";

2、修改用户缺省表空间:
SQL> Alter user acc01 default tablespace users;

3、修改用户临时表空间
SQL> Alter user acc01 temporary tablespace temp_data;

4、强制用户修改口令字:
SQL> Alter user acc01 password expire;

5、将用户加锁
SQL> Alter user acc01 account lock;  // 加锁
SQL> Alter user acc01 account unlock;  // 解锁



四、删除用户
SQL>drop user 用户名;  //用户没有建任何实体
SQL> drop user 用户名 CASCADE;  // 将用户及其所建实体全部删除

*1. 当前正连接的用户不得删除。


五、监视用户:
1、查询用户会话信息:
SQL> select username, sid, serial#, machine from v$session;

2、删除用户会话信息:
SQL> Alter system kill session 'sid, serial#';

3、查询用户SQL语句:
SQL> select user_name, sql_text from v$open_cursor;





Oracle 角色管理

一、何为角色
  角色。角色是一组权限的集合,将角色赋给一个用户,这个用户就拥有了这个角色中的所有权限。

二、系统预定义角色
  预定义角色是在数据库安装后,系统自动创建的一些常用的角色。下介简单的介绍一下这些预定角色。角色所包含的权限可以用以下语句查询:
sql>select * from role_sys_privs where role='角色名';

1.CONNECT, RESOURCE, DBA
这些预定义角色主要是为了向后兼容。其主要是用于数据库管理。oracle建议用户自己设计数据库管理和安全的权限规划,而不要简单的使用这些预定角色。将来的版本中这些角色可能不会作为预定义角色。



2.DELETE_CATALOG_ROLE, EXECUTE_CATALOG_ROLE, SELECT_CATALOG_ROLE
这些角色主要用于访问数据字典视图和包。



3.EXP_FULL_DATABASE, IMP_FULL_DATABASE
这两个角色用于数据导入导出工具的使用。



4.AQ_USER_ROLE, AQ_ADMINISTRATOR_ROLE
AQ:Advanced Query。这两个角色用于oracle高级查询功能。



5. SNMPAGENT
用于oracle enterprise manager和Intelligent Agent



6.RECOVERY_CATALOG_OWNER
用于创建拥有恢复库的用户。关于恢复库的信息,参考oracle文档《Oracle9i User-Managed Backup and Recovery Guide》



7.HS_ADMIN_ROLE
A DBA using Oracle's heterogeneous services feature needs this role to access appropriate tables in the data dictionary.



三、管理角色
1.建一个角色
sql>create role role1;


2.授权给角色
sql>grant create any table,create procedure to role1;


3.授予角色给用户
sql>grant role1 to user1;


4.查看角色所包含的权限
sql>select * from role_sys_privs;


5.创建带有口令以角色(在生效带有口令的角色时必须提供口令)
sql>create role role1 identified by password1;


6.修改角色:是否需要口令
sql>alter role role1 not identified;
sql>alter role role1 identified by password1;


7.设置当前用户要生效的角色
(注:角色的生效是一个什么概念呢?假设用户a有b1,b2,b3三个角色,那么如果b1未生效,则b1所包含的权限对于a来讲是不拥有的,只有角色生效了,角色内的权限才作用于用户,最大可生效角色数由参数MAX_ENABLED_ROLES设定;在用户登录后,oracle将所有直接赋给用户的权限和用户默认角色中的权限赋给用户。)
sql>set role role1;//使role1生效
sql>set role role,role2;//使role1,role2生效
sql>set role role1 identified by password1;//使用带有口令的role1生效
sql>set role all;//使用该用户的所有角色生效
sql>set role none;//设置所有角色失效
sql>set role all except role1;//除role1外的该用户的所有其它角色生效。
sql>select * from SESSION_ROLES;//查看当前用户的生效的角色。


8.修改指定用户,设置其默认角色
sql>alter user user1 default role role1;
sql>alter user user1 default role all except role1;
详见oracle参考文档


9.删除角色
sql>drop role role1;
角色删除后,原来拥用该角色的用户就不再拥有该角色了,相应的权限也就没有了。



说明:

1)无法使用WITH GRANT OPTION为角色授予对象权限

2)可以使用WITH ADMIN OPTION 为角色授予系统权限,取消时不是级联

附录:oracle的所有的权限
grant alter system to sxyx2008; 
grant audit system to sxyx2008; 

grant create session to sxyx2008; 
grant alter session to sxyx2008; 
grant restricted session to sxyx2008; 
grant debug connect session to sxyx2008; 

grant create tablespace to sxyx2008; 
grant alter tablespace to sxyx2008; 
grant manage tablespace to sxyx2008; 
grant drop tablespace to sxyx2008; 
grant unlimited tablespace to sxyx2008; 

grant create user to sxyx2008; 
grant become user to sxyx2008; 
grant alter user to sxyx2008; 
grant drop user to sxyx2008; 

grant create rollback segment to sxyx2008; 
grant alter rollback segment to sxyx2008; 
grant drop rollback segment to sxyx2008; 

grant create table to sxyx2008; 
grant create any table to sxyx2008; 
grant alter any table to sxyx2008; 
grant backup any table to sxyx2008; 
grant drop any table to sxyx2008; 
grant lock any table to sxyx2008; 
grant comment any table to sxyx2008; 
grant select any table to sxyx2008; 
grant insert any table to sxyx2008; 
grant update any table to sxyx2008; 
grant delete any table to sxyx2008; 
grant under any table to sxyx2008; 
grant flashback any table to sxyx2008; 

grant create cluster to sxyx2008; 
grant create any cluster to sxyx2008; 
grant alter any cluster to sxyx2008; 
grant drop any cluster to sxyx2008; 

grant create any index to sxyx2008; 
grant alter any index to sxyx2008; 
grant drop any index to sxyx2008; 

grant create synonym to sxyx2008; 
grant create any synonym to sxyx2008; 
grant drop any synonym to sxyx2008; 
grant create public synonym to sxyx2008; 
grant drop public synonym to sxyx2008; 

grant create view to sxyx2008; 
grant create any view to sxyx2008; 
grant drop any view to sxyx2008; 
grant under any view to sxyx2008; 
grant merge any view to sxyx2008; 
grant drop any materialized view to sxyx2008; 
grant create materialized view to sxyx2008; 
grant create any materialized view to sxyx2008; 
grant alter any materialized view to sxyx2008; 

grant create sequence to sxyx2008; 
grant create any sequence to sxyx2008; 
grant alter any sequence to sxyx2008; 
grant drop any sequence to sxyx2008; 
grant select any sequence to sxyx2008; 

grant create database link to sxyx2008; 
grant create public database link to sxyx2008; 
grant drop public database link to sxyx2008; 
grant alter database to sxyx2008; 
grant administer database trigger to sxyx2008; 
grant export full database to sxyx2008; 
grant import full database to sxyx2008; 


grant create role to sxyx2008; 
grant drop any role to sxyx2008; 
grant grant any role to sxyx2008; 
grant alter any role to sxyx2008; 

grant force transaction to sxyx2008; 
grant force any transaction to sxyx2008; 
grant select any transaction to sxyx2008; 

grant create procedure to sxyx2008; 
grant create any procedure to sxyx2008; 
grant alter any procedure to sxyx2008; 
grant drop any procedure to sxyx2008; 
grant execute any procedure to sxyx2008; 
grant debug any procedure to sxyx2008; 

grant create trigger to sxyx2008; 
grant create any trigger to sxyx2008; 
grant alter any trigger to sxyx2008; 
grant drop any trigger to sxyx2008; 

grant create profile to sxyx2008; 
grant alter profile to sxyx2008; 
grant drop profile to sxyx2008; 
grant drop any sql profile to sxyx2008; 
grant alter any sql profile to sxyx2008; 
grant create any sql profile to sxyx2008; 

grant create type to sxyx2008; 
grant create any type to sxyx2008; 
grant alter any type to sxyx2008; 
grant drop any type to sxyx2008; 
grant execute any type to sxyx2008; 
grant under any type to sxyx2008; 

grant create any directory to sxyx2008; 
grant drop any directory to sxyx2008; 

grant create library to sxyx2008; 
grant create any library to sxyx2008; 
grant alter any library to sxyx2008; 
grant drop any library to sxyx2008; 
grant execute any library to sxyx2008; 

grant create operator to sxyx2008; 
grant create any operator to sxyx2008; 
grant alter any operator to sxyx2008; 
grant drop any operator to sxyx2008; 
grant execute any operator to sxyx2008; 

grant create indextype to sxyx2008; 
grant create any indextype to sxyx2008; 
grant alter any indextype to sxyx2008; 
grant drop any indextype to sxyx2008; 
grant execute any indextype to sxyx2008; 

grant create dimension to sxyx2008; 
grant create any dimension to sxyx2008; 
grant alter any dimension to sxyx2008; 
grant drop any dimension to sxyx2008; 

grant manage any queue to sxyx2008; 
grant enqueue any queue to sxyx2008; 
grant dequeue any queue to sxyx2008; 

grant query rewrite to sxyx2008; 
grant global query rewrite to sxyx2008; 

grant create any context to sxyx2008; 
grant drop any context to sxyx2008; 
grant create evaluation context to sxyx2008; 
grant create any evaluation context to sxyx2008; 
grant alter any evaluation context to sxyx2008; 
grant drop any evaluation context to sxyx2008; 
grant execute any evaluation context to sxyx2008; 

grant create any outline to sxyx2008; 
grant alter any outline to sxyx2008; 
grant drop any outline to sxyx2008; 

grant create rule set to sxyx2008; 
grant create any rule set to sxyx2008; 
grant alter any rule set to sxyx2008; 
grant drop any rule set to sxyx2008; 
grant execute any rule set to sxyx2008; 
grant create rule to sxyx2008; 
grant create any rule to sxyx2008; 
grant alter any rule to sxyx2008; 
grant drop any rule to sxyx2008; 
grant execute any rule to sxyx2008; 

grant administer sql tuning set to sxyx2008; 
grant administer any sql tuning set to sxyx2008; 

grant manage file group to sxyx2008; 
grant manage any file group to sxyx2008; 
grant read any file group to sxyx2008; 

grant create job to sxyx2008; 
grant create any job to sxyx2008; 
grant create external job to sxyx2008; 

grant select any dictionary to sxyx2008; 
grant analyze any dictionary to sxyx2008; 

grant grant any privilege to sxyx2008; 
grant grant any object privilege to sxyx2008; 

grant exempt access policy to sxyx2008; 
grant exempt identity policy to sxyx2008; 

grant alter resource cost to sxyx2008; 
grant administer resource manager to sxyx2008; 

grant sysdba to sxyx2008; 

grant sysoper to sxyx2008; 

grant audit any to sxyx2008; 

grant analyze any to sxyx2008; 

grant on commit refresh to sxyx2008; 

grant resumable to sxyx2008; 

grant advisor to sxyx2008; 

grant execute any program to sxyx2008; 

grant execute any class to sxyx2008; 

grant manage scheduler to sxyx2008; 

grant change notification to sxyx2008; 

你可能感兴趣的:(数据结构,oracle,sql,Access)