数据库实验七

--(1)----------------------------------
create view 采油一矿
as
select *
from 作业项目表,单位代码表
where 单位代码 = 单据号 and 单位名称 like '采油一矿%';

create login user01 with password = '12345';
create user user00 for login user01;
grant select
on 采油一矿
to user00;
--(2)---------------------------------------------
create login login007 with password = '12345';
create user user12 for login login007
go
setuser 'user12'
go
execute _someDepCost @单位代码 = '1122',@起始日期 = '2016-5-1',@结束日期 = '2016-5-29';
execute _someDepCost @单位代码 = '112201',@起始日期 = '2016-5-1',@结束日期 = '2016-5-29';
execute _someDepCost @单位代码 = '112201001',@起始日期 = '2016-5-1',@结束日期 = '2016-5-29';
go

use zyxt
grant execute on _someDepCost
to user12
go
set user12
go

execute _someDepCost @单位代码 = '1122',@起始日期 = '2016-5-1',@结束日期 = '2016-5-29';
execute _someDepCost @单位代码 = '112201',@起始日期 = '2016-5-1',@结束日期 = '2016-5-29';
execute _someDepCost @单位代码 = '112201001',@起始日期 = '2016-5-1',@结束日期 = '2016-5-29';
go
--(3)----------------------------------------------
if OBJECT_ID('trmytr7','TR') is not null
drop trigger tr_mytr7
go
create trigger trmytr7 on 作业项目表
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
print '非工作日不能更新数据'
end
end
go
--测试数据
begin tran
update 作业项目表
set 预算人 = 'test'
where 单据号 = 'zy2017001'
if @@TRANCOUNT>0
begin
commit
end
go

 

你可能感兴趣的:(数据库作业,数据库)