MySQL Forums
Forum List  »  Triggers

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?

Options: ReplyQuote


Subject
Views
Written By
Posted
1076
August 25, 2016 03:09PM
457
August 25, 2016 06:35PM
522
August 25, 2016 10:06PM
414
August 26, 2016 08:48AM
Re: Triggers question!
513
August 26, 2016 02:51PM
496
August 26, 2016 07:26PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.