1 / 3

UNIVERSITAS MERCUBUANA PROSEDUR

UNIVERSITAS MERCUBUANA PROSEDUR Prosedur adalah program yang dapat dipanggil dieksekusi oleh program lainnya atau di eksekusi dari sql-promt seperti ISQL. Prosedur yang paling sering digunakan adalah stored-procedure yang berawalan SP dan extended stored procedure(xp), program yang

kamana
Download Presentation

UNIVERSITAS MERCUBUANA PROSEDUR

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UNIVERSITAS MERCUBUANA PROSEDUR Prosedur adalah program yang dapat dipanggil dieksekusi oleh program lainnya atau di eksekusi dari sql-promt seperti ISQL. Prosedur yang paling sering digunakan adalah stored-procedure yang berawalan SP dan extended stored procedure(xp), program yang dikompilasi sebagai exe atau DLL(Dynamic Link Library). Membuat Procedure : Create Procedure namaprocedure asa Deklarasi_variable ........... ....... .... .. ........... ....... .... .. Return Contoh : create procedure gaji as select nama, gaji from tb_karyawan return Untuk menjalankan tulis perintah EXEC dan di ikuti nama_procedure exec gaji Untuk mengkoreksi sebuah procedure, maka kunci kata alter harus digunakan . alter procedure gaji as select nama, gaji, tinggal from tb_karyawan return Untuk menghapus procedure gunakan perintah : Drop Procedure Namaprocedure Contoh : Indrianto Skom MT http://www.mercubuana.ac.id 1

  2. UNIVERSITAS MERCUBUANA nama gaji tinggal ---------- ----------- ------------ ozi 400 bandung Nilai Default Bila pada saat eksekusi procedure tidak diberikan parameter, maka para nilai parameter tersebut menjadi kosong (null). Untuk menghindari nilai null, maka pemberian nilai pada parameter dapat dapat menggunakan nilai default. alter procedure gaji ( @no int = '4' ) as begin select nama, gaji, tinggal from tb_karyawan where no = @no end exec gaji '3' Hasil : nama gaji tinggal ---------- ----------- ------------ nenny 300 jakarta Bila tidak diberikan parameter maka akan tampil sesuai dengan nilai yang telah dibuat dalam prosedur. exec gaji nama gaji tinggal Indrianto Skom MT http://www.mercubuana.ac.id 3

  3. UNIVERSITAS MERCUBUANA @Bilangan2 int, @k int output ) as select @k = @Bilangan1 + @Bilangan2 declare @hsl int exec out 30, 20, @hsl output print "Hasilnya adalah" + str(@hsl) Hasil : Hasilnya adalah 50 Berikut ini merupakan contoh yang terhubung dengan tabel : create procedure gajikaryawan @noid int ='', @gajikaryawan int output as if @noid = '' begin print " No ID Karyawan Belum Dimasukan " end select @gajikaryawan = gaji , nama from tb_karyawan where no = @noid return Eksekusi : declare @s int exec gajikaryawan '4', @s output print "Gajinya Adalah " + str(@s) Hasil : Gajinya Adalah 400 Bila Noid belum dimasukan makan akan tampil pesan swbagai berikut : Indrianto Skom MT http://www.mercubuana.ac.id 5

More Related