- 对下列两个关系模式:
- 学生(学号、班级、年龄、性别、家庭住址、班级号)
- 班级(班级号,班级名,班主任,班长)
使用grant语句完成以下授权功能:
(1)授予用户U1对两个表的所有权限,并可给其他用户授权。
grant all privileges
on Student
to U1
with grant option;
grant all privileges
on Class
to U1
with grant option;
(2)授予用户U2对学生表具有查看权限,对家庭住址具有更新权限。
grant update(address),select
on Student
to U2;
(3)将对班级表查看权限授子所有用户。
grant select
on Class
to public;
(4)将对学生表的查询、更新权限授予角色R1.
grant select,update
on Student
to R1;
(5)将角色RI授予用户UI,并且U1可继续授权给其他角色。
grant R1
to U1
with admin option;
- 有以下两个关系模式:
- 职工(职工号,姓名,年龄,职务,工资,部门号)
- 部门(部门号,名称,经理名,地址,电话号)
用sql的grant和revoke语句(加上视图机制)完成以下操作要求:
(1)用户王明对两个表有SELECT权限。
grant select
on Staff
to 王明;
grant select
on Department
to 王明;
(2)用户李勇对两个表有insert和delete权限。
grant insert,delete
on Staff
to 李勇;
grant insert,delete
on Department
to 李勇;
(3)每个职工只对自己的记录有SELECT权限。
grant select
on Staff
when user()= Name
to all;
grant select
on Department
when user()= Name
to all;
(4)用户刘星对职工表有SELECT权限,对工资字段具有更新权限。
grant update(Wages),select
on Staff
to 刘星;
(5)用户张新具有修改这两个表的结构的权限。
grant update
on Staff
to 张新;
grant update
on Department
to 张新;
(6)用户周平具有对两个表的所有权限(读、插、改、删数据),并具有给其他用户授权的权限。
grant all privileges
on Staff
to 周平
with grant option;
grant all privileges
on Department
to 周平
with grant option;
(7)用户杨兰具有从每个部门职工中SELECT最高工资、最低工资、平均工资的权限,他不能查看每个人的工资。
--建立视图View_wed
create view View_wed
as
select Department.Name,MAX(Wedge),MIN(Wedge),AVG(Wedge)
from Staff,Department
where Staff.Number=Department.Number
--授予杨兰检索权
grant select
on View_wed
to 杨兰;
- 针对上一题目中的每一种情况,撤销授权。
1.
revoke select
on Staff
from 王明;
revoke select
on Department
from 王明;
--
2.
revoke select,insert
on Staff
from 李勇;
revoke select,insert
on Department
from 李勇;
--
3.
revoke select
on Staff
when user()= Name
to all;
revoke select
on Department
when user()= Name
to all;
--
4.
revoke update , select
on Staff
to 刘星;
--
5.
revoke alter,table
on Staff
from 张新;
revoke alter,table
on Department
from 张新;
--
6.
revoke all privileges
on Staff
to 周平;
revoke all privileges
on Department
to 周平;
--
7.
revoke select
on View_Wed
from 杨兰;