user19541968
user19541968

Reputation: 15

how can i insert records of one table to another using trigger in mysql

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.

Upvotes: 0

Views: 36

Answers (1)

Ankit Bajpai
Ankit Bajpai

Reputation: 13519

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.

Upvotes: 1

Related Questions