Home > Software design >  how can i insert records of one table to another using trigger in mysql
how can i insert records of one table to another using trigger in mysql

Time:07-15

i have 1 table as emp_demo and another table as emp_demos with same columns as

eg:

emp_demo_id|emp_demo_name

 1         |  xyz     

i want to add AFTER INSERT trigger on emp_demo table so as soon as a record is inserted in emp_demo it should automatically get inserted into emp_demos table.

CodePudding user response:

CREATE TRIGGER after_insert_trig
AFTER INSERT
ON emp_demo
FOR EACH ROW
BEGIN
INSERT INTO emp_demos(emp_demo_id, emp_demo_name)
VALUES(new.emp_demo_id, new.emp_demo_name);
END;

Demo.

  • Related