SQL Server 安全性实验
《数据库系统概论》实验三 数据控制(安全性部分)姓名
日期
本实验是在实验二中的school数据库的基础上进行的,如果有需要增删改的地方将在实验中加以说明。
(一)授权与回收。
【1】 授权。建立多个用户,给他们赋予不同的权限,然后查看是否真正拥有被授予的权限了。
1) 建立用户(登录帐号)U1、U2、U3、U4、U5、U6、U7和对应的数据库school的用户dbu1、dbu2、dbu3、dbu4、dbyu5、dbu6、dbu7。
EXEC sp_addlogin 'U1','01'
use school
EXEC sp_grantdbaccess 'U1','dbu1'
EXEC sp_addlogin 'U2','02'
use school
EXEC sp_grantdbaccess 'U2','dbu2'
EXEC sp_addlogin 'U3','03'
use school
EXEC sp_grantdbaccess 'U3','dbu3'
EXEC sp_addlogin 'U4','04'
use school
EXEC sp_grantdbaccess 'U4','dbu4'
EXEC sp_addlogin 'U5','05'
use school
EXEC sp_grantdbaccess 'U5','dbu5'
EXEC sp_addlogin 'U6','06'
use school
EXEC sp_grantdbaccess 'U6','dbu6'
EXEC sp_addlogin 'U7','07'
use school
EXEC sp_grantdbaccess 'U7','dbu7'
2) 在 SYSTEM(即DBA)与七个用户之间进行授权。
把查询Student 表的权限授给用户U1。
use school
grant select on Student to dbu1
把对Student 表和Course 表的全部操作权限授予用户U2 和U3。
use school
grant insert,update,select,delete on Student to dbu2,dbu3
grant insert,update,select,delete on Course to dbu2,dbu3
把对表SC 的查询权限授予所有用户。
use school
grant select on SC to public
把查询Student 表和修改学生学号的权限授给用户U4。
use school
grant select,update(SNO) on Student to dbu4
把对表SC 的INSERT 权限授予U5,并允许U5 将此权限再授予其他用户。
use school
grant insert on SC to dbu5 with grant option
用户U5 将对表SC 的INSERT 权限授予U6,并允许将权限转授给其他用户。
首先应该以 U5 的身份重新登录数据库,然后再进行授权。
use school
grant insert on sc to dbu6 with grant option
用户U6 将对表SC 的INSERT 权限授予U7。
首先应该以U6 的身份重新登录数据库,然后再进行授权。
use school
grant insert on sc to dbu7
3) 在授权之后验证用户是否拥有了相应的权限。
在执行完上面七个语句之后,我们可以分别以不同用户的身份登录数据库,进行相关操作,检查系统是否许可。
U4 更新Student 表的学生学号。
use school
UPDATE Student
SET SNO = 1009 WHERE SNAME = '张天'
U7 向SC 表中插入一条数据:(95020,20,88)。
use school
insert into SC values(95020,20,88)
【2】 回收权限。将【1】授予的权限部分收回,检查回收后,该用户是否真正丧失了对数据的相应权限。
1) 回收权限。
收回用户U4 修改学生学号的权限。
use school
revoke update(SNO) on Student from dbu4
收回所有用户对表SC 的查询权限。
use school
revoke select on Student from public
收回用户U5 对SC 表的INSERT 权限。
use school
revoke insertonSC from dbu5 cascade
2) 在回收权限之后验证用户是否真正丧失了该权限。
用户U3 查询表SC。
use school
select *
from SC
用户U6 向表SC 中插入一条记录(‘95035’,’3’,92)。
use school
insert into SC values(95035,3,92)
(二)数据库角色。
【3】数据库角色的创建与授权。
创建数据库角色G1。
use school
EXEC sp_addrole 'G1'
给数据库角色授权,使得数据库角色G1 拥有对Student 表的SELECT、UPDATE、INSERT 的权限。
use school
grant select,update,insert,delete on Student to G1
将用户U1,U3,U7 添加到数据库角色G1 中来。
use school
EXEC sp_addrolemember 'G1','dbu1'
EXEC sp_addrolemember 'G1','dbu3'
EXEC sp_addrolemember 'G1','dbu7'
对数据库角色G1 的权限进行修改,增加对Student 表的DELETE 权限,并回收对Student表的INSERT 权限。
use school
grant delete on Student to G1
revoke inserton Student from G1 cascade
页:
[1]