Re: Triggers question!
Posted by:
Max Molina
Date: August 26, 2016 02:51PM
man, you've helped me more than the entirety of stack overflow.
I have succesfully created the trigger in question and i Understand a lot better how triggers work. I even managed to fix several errors myself. Now im in a bit of a pickel, though.
With this trigger>
BEGIN
IF (NEW.IMHQ_solicitado = 'SI')
THEN
INSERT INTO imhq (ID_CASO,Tipo_de_estudio,Año,Codigo_interno,Iniciales_Px,Sexo,Edad,n_marcadores_solicitados)
VALUES (NEW.ID_CASO, NEW.Tipo_de_estudio, NEW.Año, NEW.Codigo_Interno, NEW.Iniciales_Px, NEW.Sexo, NEW.Edad,NEW.n_marcadores_solicitados);
END IF;
IF (NEW.FISH_solicitado = 'SI')
THEN
INSERT INTO fish (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
as you can see im adding the ID_CASO column, which is the primary key of master_table. I need that record cpied exactly as it is into the child tables. It is returning 0 how ever(on master table the ID_CASO value is added perfectly),or it gives me a foreign key restriction violated error if the tables are related, with a foreign key. I undid that and it now allows record insertion in parent and child table but the ID_CASO value from master_table is not going into its child table 'imhq'.
the column on master table is set to integer 4 length auto increment.
Is there a way to do this while retaining the foriegn key?