sql - Mysql insert data on table a when insert in table b -
i want this: if not exist data on table mislibros insert value idebook table ebook, when try call mysql says :#1054 - unknown column 'ebook.idebook' in 'where clause'
pd: don't want use update, need insert
create procedure spexistencia ( ) begin start transaction; if not exists (select idebook mislibros ebook.idebook= mislibros.idebook) insert mislibros (idebook) values (new.idebook); else signal sqlstate '45000' set message_text= 'ya cuentas con el libro seleccionado'; end if; commit; end;
check create trigger syntax example.
try this:
delimiter $$ drop trigger /*!50032 if exists */ `tr_ebook`$$ create trigger `tr_ebook` after insert on `ebook` each row begin if not exists (select 1 mislibros new.idebook = mislibros.idebook) insert mislibros (idebook) values (new.idebook); end if; end; $$ delimiter ;
Comments
Post a Comment