This is default featured post 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Selasa, 26 Juni 2012

trigger sql

membuat trigger baru
create trigger trigoninsbeli after insert on beli for each row
begin
    SELECT namasupplier into @namasupplier FROM supplier WHERE     kodesupplier=NEW.kodesupplier;
    insert into jurnal set keterangan=concat('Pembelian dari supplier dengan nama ',     @namasupplier), notransaksi=NEW.nobeli,jenistransaksi='Beli';
end
delimiter ;$$
' maksutnya create trigger (ciptakan trigger) trigoninsbeli (nama trigger yang dibuat : trigoninsbeli) after insert on beli ( trigger di jalankan setelah ada input di tabel beli) for each row ( pada setiap baris)
begin

 SELECT namasupplier (memilih yang ditampilkan exampler: namasuplliyer ) into @namasupplier (dengan definisi @namasupllier) FROM supplier ( dari tabel supplier ) WHERE ( dimana kondisinya )    kodesupplier=NEW.kodesupplier (kodesupplier = kodesupplier yang baru);
    insert into jurnal (input data ke tabel jurnal) set (atur) keterangan=concat(pengabungan column) ('Pembelian dari supplier dengan nama ',     @namasupplier), notransaksi=NEW.nobeli,jenistransaksi='Beli';

end


create trigger trigoninsdetbeli after insert on detbeli for each row begin
    select nojurnal into @nojurnal from jurnal where notransaksi=new.nobeli and jenistransaksi='Beli';
    select sum(qty*harga) into @jumlah from detbeli where nobeli=new.nobeli;
    replace into detjurnal set nojurnal=@nojurnal,kodeakun='5000',dk='D',jumlah=@jumlah;
    replace into detjurnal set nojurnal=@nojurnal,kodeakun='1000',dk='K',jumlah=@jumlah;
 
end
delimiter ;$$

create trigger trigoninsjual after insert on jual for each row
begin
    SELECT namapelanggan into @namapelanggan FROM pelanggan WHERE     kodepelanggan=NEW.kodepelanggan;
    insert into jurnal set keterangan=concat('Penjualan ke pelanggan dengan nama ',     @namapelanggan), notransaksi=NEW.nojual,jenistransaksi='Jual';
end
delimiter ;$$

create trigger trigoninsdetjual after insert on detjual for each row begin
    select nojurnal into @nojurnal from jurnal where notransaksi=new.nojual and jenistransaksi='Jual';
    select sum(qty*harga) into @jumlah from detjual where nojual=new.nojual;
    replace into detjurnal set nojurnal=@nojurnal,kodeakun='4000',dk='K',jumlah=@jumlah;
    replace into detjurnal set nojurnal=@nojurnal,kodeakun='1000',dk='D',jumlah=@jumlah;
 
end
delimiter ;$$

untuk memanggil trigger:
show triggers;

Minggu, 17 Juni 2012

function+procedure SQL

Procedure
membuat procedure :

CREATE PROCEDURE namabarang(IN kode varchar(10), OUT nama VARCHAR(30))
Begin
select namabarang INTO nama from barang where kodebarang=kode;
end

delimiter$$

 maksutnya :
"create procudre namaprocedure (IN'di input pada' exp: kode ,OUT'keluaranya pada column ' exp: nama)
begin
 select namabarang INTO 'dari isi column'exp: nama dari nama tabel WHERE'dimana' kodebarang=kode;
end

 memanggil  procdure:
CALL namabarang('B001',@nama);
SELECT @nama;

 maksutnya :
CALL nama procedure(kodenya exp:'B001',dengan tampilan exp:'nama');
SELECT(tampilkan) @nama;



CREATE PROCEDURE jumlahbarang(IN kode varchar(10), OUT param VARCHAR(30))
Begin
select CONCAT(namabarang, 'jumlah= ',jumlahstok) INTO param from barang where kodebarang=kode;
end

delimiter$$

 memanggil  procdure:
CALL jumlahbarang('B001',@info);
SELECT @info;


 menghapus procedure:
DROP Procedure namaprocedure;

pengertian FUNCTION

CREATE FUNCTION fnamabarang (kode VARCHAR(10)) RETURNS VARCHAR(30)
BEGIN
 select namabarang INTO @nama FROM barang WHERE kodebarang=kode;
 RETURN @nama;
END

 memanggil function :
SELECT namabarang('B001');

Twitter Delicious Facebook Digg Stumbleupon Favorites More