Ad (728x90)

Minggu, 04 November 2012

Filled Under:

Jawaban Latihan (5)


-- No. 1
--procedure sp_GetMKPerDosen untuk menghitung seluruh data MK
create proc sp_GetMKPerDosen @nid as char(6)
as
begin
--menampilkan data MK berdasarkan dosen yang diinputkan
select distinct d.nama, mk.kode_mk, mk.nama, mk.sks, mk.semester
from mk, nilai n, dosen d
where mk.kode_mk = n.kode_mk and
n.nid = d.nid and
d.nid = @nid --'010103'

--deklarasi variabel untuk menampung jumlah MK berdasarkan dosen yang diinputkan
declare @jumlah as numeric;

--set nilai jumlah
set @jumlah = (select count(distinct mk.kode_mk)
from mk, nilai n, dosen d
where mk.kode_mk = n.kode_mk and
n.nid = d.nid and
d.nid = @nid) --'010103'
print 'Jumlah MK yang diambil dosen adalah ' + convert(char,@jumlah)
end

--eksekusi procedure sp_GetMKPerDosen
--cara 1
sp_GetMKPerDosen '010306'
--cara 2
exec sp_GetMKPerDosen '010103'

--hapus procedure sp_GetMKPerDosen
drop proc sp_GetMKPerDosen

--No. 2
--procedure sp_insertDosen untuk memasukan data dosen
create proc sp_insertDosen @nid as char(6), @nama as varchar(100)
as
begin
insert into dosen
values (@nid, @nama)
end

--lihat data dosen
select * from dosen

--eksekusi procedure sp_insertDosen
sp_insertDosen '123456','Edo Yonatan K.';

--lihat data dosen
select * from dosen

--hapus procedure sp_insertDosen
drop proc sp_insertDosen

--No. 3
--procedure sp_DnsertDosen untuk menghapus data dosen
create proc sp_DeleteDosen @nid as char(6)
as
begin
delete from dosen where nid = @nid
end

--lihat data dosen
select * from dosen

--eksekusi procedure sp_DeleteDosen
sp_DeleteDosen '123456';

--lihat data dosen
select * from dosen

--hapus procedure sp_DeleteDosen
drop proc sp_DeleteDosen

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.