Insert error_msg values ('Data sedang digunakan tabel lain');
Insert error_msg values ('Data tidak ada dalam parameter');
Table login (Table Anak)
CREATE TABLE `login`(
`username` VARCHAR(50) NOT NULL,
`password` VARCHAR(50) NOT NULL,
`id_user` INT(11) NOT NULL,
PRIMARY KEY (`username`)
)
ENGINE=MyISAM;
INSERT INTO `testdb`.`login` (`username`, `password`, `id_user`)
VALUES ('SWW', '123', 1);
Table user (Table Induk)
CREATE TABLE `user` (
`id_user` INT(11) NOT NULL AUTO_INCREMENT,
`nama` VARCHAR(50) NULL DEFAULT NULL,
PRIMARY KEY (`id_user`)
)
COLLATE='latin1_swedish_ci'
ENGINE=MyISAM
AUTO_INCREMENT=2;
INSERT INTO `testdb`.`user` (`id_user`, `nama`) VALUES (1, 'HUSNIAH');
INSERT INTO `testdb`.`user` (`id_user`, `nama`) VALUES (2, 'RANUAH');
2. The third step , namely : make 4 pieces trigger .
Trigger delete parent table
CREATE TRIGGER `delete_induk` BEFORE DELETE ON `user` FOR EACH ROW BEGIN
IF(SELECT COUNT(*) FROM login WHERE login.id_user = old.id_user)>0 THEN
insert error_msg VALUES('Data sedang digunakan tabel lain');
END IF;
END