0
I have the following situation :
The tables described above are ger_usuario, ger_mensagem and ger_destinos.
Being, the field proprietario (ger_mensagem) a FOREIGN KEY referencing the table ger_usuario.
Being, the field id_destino (ger_mensagem) a FOREIGN KEY referencing the table ger_destinos.
I need a Trigger to search the value of the last id_destino (ger_destinos) only then add it to the table ger_mensagem. In case the proprietario will be compared via code.
I made that Trigger :
DELIMITER $$
CREATE TRIGGER manut_destino BEFORE INSERT
ON ger_mensagem
FOR EACH ROW
BEGIN
DECLARE var_dest INT;
INSERT INTO ger_destinos VALUES ('','',0);
SELECT id_destino INTO var_dest FROM ger_destinos ORDER BY id_destino DESC;
INSERT INTO ger_mensagem VALUES ('','NEW.assunto','NEW.cat','NEW.rec','NEW.data_cria',
'NEW.del','NEW.del_nom','NEW.del_data',1,var_dest);
end $$
But it presents the following error :



