Ad (728x90)

Senin, 12 November 2012

Filled Under:

Tugas pert 6



--------------------------------------------------------------------

alter trigger update_quo on detil_peminjaman
after insert
as
begin
declare @nim char (11)
declare @kode_buku numeric (18,0)
declare @no_pinjam char (11)
set @no_pinjam = (select no_peminjaman from inserted)
set @nim = (select mahasiswa from peminjaman where no_peminjaman = @no_pinjam)
set @kode_buku = (select id_buku from inserted)
exec update_quota @nim
exec update_buku @kode_buku

end

--------------------------------------------------------------------

alter procedure update_quota (@nim char(11))
as
begin
declare @jum int
--set @jum = (select quota_perpus from mahasiswa where nim = @nim)
update mahasiswa set quota_perpus = quota_perpus-1 where nim = @nim
end

--------------------------------------------------------------------

alter procedure update_buku (@id_buku numeric (18,0))
as
begin
update buku set jumlah = jumlah -1 where id = @id_buku
end

--------------------------------------------------------------------

insert into peminjaman values ('124', getdate(), '05410104001')

insert into detil_peminjaman values ('124', '1', '0')

--------------------------------------------------------------------

alter trigger cek_quotaMhs on detil_peminjaman
instead of insert
as
begin
declare @nim char (11)
declare @no_pinjam char (11)
declare @jumlah_quota int
declare @kode_buku numeric (18,0)
declare @denda numeric (18,0)
set @no_pinjam = (select no_peminjaman from inserted)
set @nim = (select mahasiswa from peminjaman where no_peminjaman = @no_pinjam)
set @jumlah_quota = dbo.jumlah_quotaMhs (@nim)
set @kode_buku = (select id_buku from inserted)
set @denda = (select denda from inserted)
if @jumlah_quota = 0
begin
exec hapus_peminjaman @no_pinjam
end
else if  @jumlah_quota >0
insert into detil_peminjaman values (@no_pinjam, @kode_buku, @denda )

end

--------------------------------------------------------------------
alter function jumlah_quotaMhs (@nim char (11))
returns int
as
begin
declare @jumlah int
set @jumlah = (select quota_perpus from mahasiswa where nim = @nim)
return @jumlah
end

--------------------------------------------------------------------

alter procedure hapus_peminjaman (@no_pinjam char(10))
as
begin
delete from peminjaman where no_peminjaman = @no_pinjam
end

--------------------------------------------------------------------

insert into peminjaman values ('298', getdate(), '05410104001')

insert into detil_peminjaman values ('298', '2', 0)

Antonius Jefry

Author & Editor

Has laoreet percipitur ad. Vide interesset in mei, no his legimus verterem. Et nostrum imperdiet appellantur usu, mnesarchum referrentur id vim.

0 komentar:

Posting Komentar

 

We are featured contributor on entrepreneurship for many trusted business sites:

  • Copyright © JSC BOJONEGORO™ is a registered trademark.
    Designed by Templateism. Hosted on Blogger Platform.