php - DROP and CREATE the same trigger in the same sintaxis -


dummy question: have next code in mysql, when run in heidisql, show sintaxis error near '// create trigger'. i'm not sure if happen because trigger doesn't exists. code:

drop trigger if exists oportunidades_movimiento_entregado // create trigger oportunidades_movimiento_entregado; after insert on historial_entregado each row begin update oportunidades set oportunidades.fechamodificado = new.fecha_creacion new.oportunidad_id = oportunidades.id; end// 

update

delimiter $$ drop trigger if exists oportunidades_movimiento_entregado $$ create trigger oportunidades_movimiento_entregado after insert on historial_entregado each row begin update oportunidades set oportunidades.fechamodificado = new.fecha_creacion new.oportunidad_id = oportunidades.id; end; $$ delimiter // 

this works, doubt is... code (the drop , create) run everytime, or create? need because i'm working 2 tables, in 1 of them insert/update data, after trigger insert of columns in table keep historial, when make insert or update query in first table, mysql display error #1442

can't update table oportunidades in stored/function trigger because it's used statement invoked stored function/trigger.

to working, set delimiter first , reset after create trigger statement. remove semicolon @ end of create trigger line.

this should work:

delimiter // drop trigger if exists oportunidades_movimiento_entregado //  create trigger oportunidades_movimiento_entregado    -- no trailing semicolon here     after insert on historial_entregado     each row begin         update oportunidades         set oportunidades.fechamodificado = new.fecha_creacion         new.oportunidad_id = oportunidades.id;     end//  delimiter ; 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -