How to create a trigger that updates the fields of one table with another?

0

This is my first question here, well to the point, for the class of Databases II I need to create a trigger in MySQL that when inserting data in the student table the table of student support is also updated, I know it can be a Maybe it's very X question but I would appreciate your help:

CREATE TRRIGER alumupdate AFTER UPDATE ON alumno UPDATE respaldo_alumno SET nombre=UPDATE.NOMBRE,direccion=UPDATE.DIRECCION,codigo=UPDATE.CODIGO WHERE codigo=alumno.codigo

This is the code of my trigger, if you can guide me or tell me that I have to correct it, I would appreciate it

    
asked by Fernando De Jesus Basurto 14.04.2018 в 20:28
source

1 answer

0

What I understand is that when inserting in students, it is also inserted in student support, if it is true, try this example in version 5.6

DELIMITER $$

CREATE TRIGGER alumupdate AFTER INSERT ON alumnos FOR EACH ROW BEGIN INSERT INTO student_ support (code, name, address) VALUES (NEW.codigo, NEW.name, NEW.direccion); END $$

DELIMITER;

Before you create the corresponding tables so that the trigger can work, basically when you insert in Students it will be reflected automatically in student support.

Greetings!

    
answered by 15.04.2018 / 07:34
source