1. 程式人生 > >資料庫實驗七

資料庫實驗七

--(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