0

I get an error when inserting a row into a table after creating this trigger:

DELIMITER $$
CREATE TRIGGER aio_mtltp2016 AFTER INSERT ON master_table_linfomastp2016
BEGIN
        IF master_table_linfomastp2016 (IMHQ_solicitado = 'SI')
        THEN 
        INSERT INTO imhq (ID_CASO,Tipo_de_estudio,Año,Codigo_interno,Iniciales_Px,Sexo,Edad)
        VALUES (NEW.ID_CASO, NEW.Tipo_de_estudio, NEW.Año, NEW.Codigo_Interno, NEW.Iniciales_Px, NEW.Sexo, NEW.Edad);
        END IF;
END;$$
DELIMITER ;

The record im inserting is as follows:

INSERT INTO `master_table_linfomastp2016` (`ID_CASO`, `Tipo_de_estudio`, `Año`, `Codigo_interno`, `Iniciales_Px`, `Sexo`, `Edad`, `Servicio_solicitante`, `Roche_Hospital`, `Especimen`, `Macro`, `Diagnóstico`, `subtipo_ltp`, `FISH_solicitado`, `IMHQ_solicitado`, `laminilla_encontrada`, `laminilla_revisada`, `bloque_recibido`, `punch_realizado`, `en_microarreglo`, `validado_por`, `n_marcadores_solicitados`, `Localizacion`, `registro_HU`) VALUES (NULL, 'P', '15', '9106', 'IAS', 'M', '34', 'Hospital Universitario', NULL, 'BIOPSIA', 'REVISION DE LAMINIALLAS', 'LINFOMA NO HODGKIN T PERFIERICO NO ESPECIFICADO', 'Celulas T perifericas (Sin otra especificacion)', 'NO', 'SI', 'NO', 'NO', 'NO', 'NO', 'NO', 'JPF', '12', 'NODAL', '1383250-3')

and it says:

#1305 - FUNCTION linfomas_t_bd.master_table_linfomastp2016 does not exist

where did i go wrong? the insertion of records works if i remove the trigger, but I cannot insert records after creating the trigger and it gives me that error.

If i change the syntax from ` to ' it gives me syntax error. It also says sometimes that the table does not exist. What am i doing wrong? Im using phpMyAdmin but the trigger I made was using direct mysql input, not the trigger creator. The trigger is created without problems.

1
  • 1
    Shouldn't you just check the New.IMHQ_solicitado = 'SI' in the IF statement? The trigger is for the table master_table_linfomastp2016, so there is no need to reference that in the IF statement.
    – SS_DBA
    Commented Aug 26, 2016 at 17:07

1 Answer 1

1

The IF statement should only check the column that is being inserted for 'SI', see revised code.

DELIMITER $$
CREATE TRIGGER aio_mtltp2016 AFTER INSERT ON master_table_linfomastp2016
BEGIN
        IF New.IMHQ_solicitado = 'SI'
        THEN 
        INSERT INTO imhq (ID_CASO,Tipo_de_estudio,Año,Codigo_interno,Iniciales_Px,Sexo,Edad)
        VALUES (NEW.ID_CASO, NEW.Tipo_de_estudio, NEW.Año, NEW.Codigo_Interno, NEW.Iniciales_Px, NEW.Sexo, NEW.Edad);
        END IF;
END;$$
DELIMITER ;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.