【數據庫作業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;

錯誤

此處容易犯錯:

revoke all privileges
on worker,apartment
from Zhouping cascade;

(7)用戶楊蘭具有從每個部門職工中SELECT最高工資,最低工資,平均工資的權限,他不能查看每個人的工資。

revoke select
on sala
from Yanglan;

批改後分析:由於習慣使用了適合sql sever的語句而沒有使用標準SQL語句,在對多個表授權的時候是分開寫的,此處應該注意,考試的時候應該用標準sql。而且標準sql的on後需要加table。另外在使用with grant option授權後,在撤銷權限時,應該使用cascade級聯撤銷,而不是直接在後面加with grant option,此處容易犯錯。

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