作业12

1、对下列两个关系模式:
学生(学号,姓名,年龄,性别,家庭住址,班级号)
班级(班级号,班级名,班主任,班长)
使用GRANT语句完成下列授权功能:
(1)授予用户U1对两个表的所有权限,并可给其他用户授权。
grant all privileges
on student,class
to U1
with grant option;
(2)授予用户U2对学生表具有查看权限,对家庭住址具有更新权限。
grant select,update(adress)
on student
to U2;
(3)将对班级表查看权限授予所有用户。
grant select
on class
to public;
(4)将对学生表的查询、更新权限授予角色R1。
create role R1;
grant select,update
on student
to R1;
(5)将角色R1授予用户U1,并且U1可继续授权给其他角色。
grant R1
to U1
with grant option;
2、今有以下两个关系模式:
职工(职工号,姓名,年龄,职务,工资,部门号)
部门(部门号,名称,经理名,地址,电话号)
请用SQL的GRANT和REVOKE语句(加上视图机制)完成以下授权定义或者存取控制功能:
(1)用户王明对两个表有SELECT权限。
grant select
on worker
to WangMing
grant select
on apartment
to WangMing;
(2)用户李勇对两个表有INSERT和DELETE权限。
grant insert,delete
on worker
to Liyong
grant insert,delete
on apartment
to Liyong;
(3)每个职工只对自己的记录有SELECT权限。
grant select
on worker
to public;
(4)用户刘星对职工表有SELECT权限,对工资字段具有更新权限。
grant select,update(salary)
on worker
to Liuxing;
错误
查询答案:
GRANT SELECT ON 职工
WHEN USER()=NAME
TO ALL;

另外通过他人提示我感觉这个题是不是可以用视图来解决(保留意见):
create view new1
as
select *
from worker
where worker.wno = ‘wno’
grant select
on new1
to public;
(5)用户张新具有修改这两个表的结构的权限。
grant update
on worker
to Zhangxin
grant update
on apartment
to Zhangxin;
(6)用户周平具有对这两个表的所有权限(读、插、改、删数据),并具有给其他用户授权的权限。
grant all privileges
on worker
to Zhouping
with grant option;
grant all privileges
on apartment
to Zhouping
with grant option;
(7)用户杨兰具有从每个部门职工中SELECT最高工资,最低工资,平均工资的权限,他不能查看每个人的工资。
create view sala
as
select(max(salary),min(salary),avg(salary))
from worker,apartment
where worker.ano=apartment.ano;
grant select
on sala
to Yanglan;
3、针对2,撤销各用户所授予的权限。
(1)用户王明对两个表有SELECT权限。
revoke select
on worker
from WangMing
revoke select
on apartment
from WangMing;
(2)用户李勇对两个表有INSERT和DELETE权限。
revoke insert,delete
on worker
from Liyong
revoke insert,delete
on apartment
from Liyong;
(3)每个职工只对自己的记录有SELECT权限。
revoke select
on worker
from public;
错误
查询答案:
REVOKE SELECT ON 职工
WHEN USER()=NAME
FROM ALL;
(4)用户刘星对职工表有SELECT权限,对工资字段具有更新权限。
revoke select,update(salary)
on worker
from Liuxing;
(5)用户张新具有修改这两个表的结构的权限。
revoke update
on worker
from Zhangxin
revoke update
on apartment
from Zhangxin;
(6)用户周平具有对这两个表的所有权限(读、插、改、删数据),并具有给其他用户授权的权限。
revoke all privileges
on worker
from Zhouping
with grant option;
revoke all privileges
on apartment
from Zhouping
with grant option;
(7)用户杨兰具有从每个部门职工中SELECT最高工资,最低工资,平均工资的权限,他不能查看每个人的工资。
revoke select
on sala
from Yanglan;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章