Professional Documents
Culture Documents
Lab 5
Lab 5
2)
create view depositDetails as
select count(h.accno) 'No of accounts'
from Has h, Account a
where h.accno = a.accno and h.type_ = 'credit'
group by a.code
3)
create function fn_totalAccBalance(@branchNo int,@bankCode int ) returns real
as
begin
declare @tot real
return @tot
end
4)
create function fn_totalWithdrawals(@year date, @accNo int, @method varchar(10))
returns real
as
begin
declare @tId int
declare @tot real
select @tId = tid from Has where accno = @accNo
select sum(amount)
from Transaction_
where date_ = @year and exec_by = @method and tid = @tid
return @tot
end
5)
create procedure updateAccount(@accNo int, @amount real, @operation varchar(10))
as
begin
if (@operation = 'credit')
begin
update Account
set balance = balance + @amount
where accno = @accNo
end
else
begin
update Account
set balance = balance - @amount
where accno = @accNo
end
end
6)
create procedure transferMoney(@transferAmount real,@transferFrom int,
@transferTo int)
as
begin
update Account
set balance = balance - @transferAmount
where accno = @transferFrom
update Account
set balance = balance + @transferAmount
where accno = @transferTo
end
7)
create trigger checkRemainBalance
on Account
for insert, update
as
begin
declare @bal real
9)
create trigger upadateBalance
on Has
for insert
as
begin
declare @type varchar(20)
declare @accNo int
declare @amount real
declare @tId int
select @type = type_, @accNo = accountNO, @tId = tid from
inserted
if (@type = 'credit')
begin
update Account
set balance = balance + @amount
where accno = @accNo
end
else
begin
update Account
set balance = balance - @amount
where accno = @accNo
end
end