您的当前位置:首页正文

中国石油大学华东数据库实验七龚安

来源:易榕旅网
实验七 安全机制

1.理解登录、用户、架构、角色、权限的概念,在Enterprise Manager里浏览SQL Server 2005中存在的登录名、用户、架构、角色和权限,形成一个总结。

2.利用Query Analyzer完成以下操作:

⑴ 建立采油一矿的作业项目的视图,把该视图的查询权限授予给采油一矿的用户user11,以user11的身份查询该视图,观察执行情况;再以其他用户的身份查询该视图,观察执行情况。

create view caiyouyikuangshitu

as

select

zuoyexiangmuhao,yusuandnawei,jinghao,yusuanjine,yusuanren,yusuanriqi,

kaigongriqi,wangongriqi,shigongdanweimingcheng,shigongneirong,cailiaofei,rengongfei,shebeifei,

qitafei,jiesuanjine,jiesuanren,jiesuanriqi,jingbie,danweimingcheng

from xiangmubiao,youshuijingbiao,danweidaimabiao

where yusuandanwei=youshuijingbiao.danweidaima and

yusuandanwei=danweidaimabiao.danweidaima;

CREATE LOGIN user01 WITH PASSWORD='12345';

CREATE USER user11 FOR LOGIN user01;

grant select

on caiyouyikuangshitu

to user11;

⑵ 创建一个用户user12,以user12的身份执行实验六中所定义的存储过程,观察记录是否成功执行;然后把该存储过程的执行权限授予给user12,再次以user12的身份执行该存储过程,观察记录是否成功执行。

--创建用户user12

create user user12 for login xxx

go

--授权之前执行存储过程,fail after below error.

setuser 'user12'

go

execute

@dwdm='1122',@starttime='2011-5-1',@endtime='2011-5-29';

_someDepCost

execute _someDepCost

@dwdm='112201',@starttime='2011-5-1',@endtime='2011-5-29';

execute _someDepCost

@dwdm='112201001',@starttime='2011-5-1',@endtime='2011-5-29';

go

/*消息229,级别14,状态5,过程_someDepCost,第1 行

拒绝了对对象'_someDepCost' (数据库'zyxt',架构'dbo')的EXECUTE 权限。

消息229,级别14,状态5,过程_someDepCost,第1 行

拒绝了对对象'_someDepCost' (数据库'zyxt',架构'dbo')的EXECUTE 权限。

消息229,级别14,状态5,过程_someDepCost,第1 行

拒绝了对对象'_someDepCost' (数据库'zyxt',架构'dbo')的EXECUTE 权限。*/

--授权给user12 对存储过程_someDepCost的execute权限,success

use zyxt

grant execute

on _someDepCost

to user12

go

--授权之后执行存储过程,success

setuser 'user12'

go

execute

@dwdm='1122',@starttime='2011-5-1',@endtime='2011-5-29';

_someDepCost

execute _someDepCost

@dwdm='112201',@starttime='2011-5-1',@endtime='2011-5-29';

execute _someDepCost

@dwdm='112201001',@starttime='2011-5-1',@endtime='2011-5-29';

go

⑶ 定义触发器,实现只能在工作时间内更新“作业项目表”的数据,然后通过选择不同的时间进行适当的更新操作来验证。

if OBJECT_ID('tr_mytr7','TR')is not null

drop trigger tr_mytr7

go

create trigger tr_mytr7

on xiangmubiao

after update

as

declare @currenttime datetime

set @currenttime=getdate();

declare @current_day varchar(10)

set @current_day=convert(varchar(10),datepart(dw,@currenttime)-1);

if @current_day not between 1 and 5

begin

if @@trancount>0

begin

rollback transaction

print '非工作日不能更新数据'

end

end

go

--测试数据(要通过更改系统的时间进行测试)success

begin transaction

update xiangmubiao

set yusuanren='豆豆'

where zuoyexiangmuhao='zy2011001'

if @@trancount>0

begin

commit

end

go

因篇幅问题不能全部显示,请点此查看更多更全内容