控制用户权限
1.创建用户
1)
SQL> create user atguigu01
2 identified by atguigu01;
User created
2)
SQL> grant create session
2 to atguigu01;
Grant succeeded
3)
SQL> grant create table
2 to atguigu01;
Grant succeeded
4)
SQL> alter user atguigu01 quota 5m
2 on users;
User altered
2.创建角色
1)
SQL> create role my_role;
Role created
2)
SQL> grant create session,create table,create view to my_role;
Grant succeeded
3)
SQL> create user atguigu02
2 identified by atguigu02;
User created
4)
SQL> grant my_role to atguigu02;
Grant succeeded
SQL>
3.使用GRANT 和 REVOKE 语句赋予和回收权限
1)
SQL> grant select,update
2 on scott.employees
3 to atguigu01;
Grant succeeded
2)
SQL> grant select
2 on scott.departments
3 to atguigu01
4 with grant option;
Grant succeeded
3)
SQL> grant select,update
2 on locations
3 to public;
Grant succeeded
4)
SQL> revoke select
2 on employees
3 from atguigu01;
Revoke succeeded
作业:
- 1.如果用户能够登陆到数据库,至少需要哪种权限?是系统权限还是对象权限
CREATE SESSION 系统权限 - 2.创建表需要哪种权限?
CREATE TABLE - 3.将表departments的查询权限分配给用户system
Grant select
on departments
to system;
- 4.从system处收回刚才赋予的权限
REVOKE select
on departments
from system;
- 5.创建角色dvp,并将如下权限赋予该角色
CREATE PROCEDURE
CREATE SESSION
CREATE TABLE
CREATE SEQUENCE
CREATE VIEW
1)
CREATE ROLE dvp;
2)
GRANT CREATE PROCEDURE,CREATE SESSION,CREATE TABLE,CREATE SEQUENCE,CREATE VIEW
TO dvp;