Trigger After Delete on MySQL

It quite difficult to hear somebody explain about Trigger or Stored Procedure inDatabase Management System (DBMS). But step by step we learn, we can do it.

In this Simple Post, I'll try to make an easy Trigger After Deleting data on MySQL.

The Process Was a Copying into a table : If Any Row Delete happen in Main Table, Trigger a Copy Row into a Table named like Tbl_Deleted.

Below Was The Trigger.

DELIMITER $

DROP TRIGGER /*!50032 IF EXISTS */ `db_wisuda`.`del_biodata`$$

CREATE
/*!50017 DEFINER = 'root'@'localhost' */
TRIGGER `del_biodata` AFTER DELETE ON `tb_name`
FOR EACH ROW BEGIN
delete from tb_user where username = old.nim;

insert into tb_name_del
(id,
name,
terbaik,
nopenanda
)
values
(old.idbiodata,
old.name,
old.terbaik,
old.nopenanda
);
END;
$$

DELIMITER ;


The Process was simple, If delete happen in tb_name, delete the users in tb_user and copy the data that has been deleted to tb_name_del.

Old mean the table that has been delete.
You can see username=old.nim

i have the tb_user that the tb_user username = tb_name.nim

Komentar FB


Probably Related Article



0 comments:

Related Posts by Categories



Widget by