0
I am trying to create a Trigger in Mysql where I need in updating a table (I will call tb1) depending on the situation field, delete a record in another database from a table.
Base 1 = B1
Table 1 = Tb1
Base 2 = B2
Table 2 = Tb2
-- Trigger I’m trying to create
CREATE TRIGGER trigger_agendamento_vinculo_situacao AFTER UPDATE ON B1.TB1 for each row begin
if (new.situacao <> 'ativo') THEN
delete from B2.TB2 where username = NEW.prontuario_original;
end;
But every time I try to create Mysql it shows the following error:
CREATE TRIGGER B1.TB1.trigger_schedule_vinculo_situacao AFTER UPDATE ON B1.TB1 for each Row Begin if (new.situation <> 'asset') THEN delete from B2.TB2 Where username = NEW.ready_original Error Code: 1064. You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use near '' at line 3 0.000 sec
What version of Mysql database are you using?
– Ismael SIlva
The Mysql database is '5.5.38-0ubuntu0.12.04.1-log'
– Ricardo Facincani
I think Mysql doesn’t "like" many unnecessary spaces. Check if you happen to have extra spaces...
– João Martins
I’ve tried, I’ve done it like it’s a single line, but it doesn’t work.
– Ricardo Facincani
You tried with the
DELIMITER
?– Roberto de Campos
I could not format for better visualization
delimiter | 
CREATE TRIGGER trigger_agendamento_vinculo_situacao AFTER UPDATE ON B1.TB1 for each row begin 
if (new.situacao <> 'ativo') THEN delete from B2.TB2 where username = NEW.prontuario_original; end;
 delimiter ;
– Ricardo Facincani