Membuat Trigger

Posted: Januari 9, 2012 in Uncategorized

create database mytrigger;

create table coba (
kode varchar(5) not null,nama varchar(35) not null,
primary key (kode))

create table coba2 (
kode varchar(5) not null,nama varchar(35) not null,
primary key (kode))

create table tran (
kode varchar(5) not null,
kodetran varchar(5),jumlah double,
primary key nkode (kode,kodetran))

delimiter $$

create trigger auto_insert_coba2
before insert on coba for each row
begin
  insert into coba2 (kode,nama) values (NEW.kode,NEW.nama);
end$$

create trigger auto_update_coba2
before update on coba for each row
begin
  update coba2 set nama=NEW.nama where kode=NEW.kode;
end$$

create trigger auto_delete_coba2
before delete on coba for each row
begin
delete from coba2 where kode=OLD.kode;
delete from tran where kode=OLD.kode;
end$$

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s