mysql triggers to multiple table and insert new id to table I have 4 table:

table a (id (auto_increment), id_b , id_c, id_d(foreign_key from table b,c,d) , column)
table b (id auto_increment, column)
table c (id auto_increment, column)
table d (id auto_increment, column)


when there's event table a, b, c, d inserted, must copy to table a, b, c, d in other database. (note: in other database table a,b,c,d already has data, so auto_increment isn't identical to current database)

I want to create triggers for that, but I'm confused how can I fill id_b, id_c, id_d from table b, c, d in other database
CREATE TRIGGER tr_b
AFTER INSERT
ON db1.table_b
FOR EACH ROW
INSERT IGNORE INTO db2.table_b (column)
VALUES (NEW.column);


The same for table_c and table_d.

CREATE TRIGGER tr_a
AFTER INSERT
ON db1.table_a
FOR EACH ROW
INSERT INTO db2.table_a (id_b, id_c, id_d, column)
SELECT b.id, c.id, d.id, vals.column_a
FROM ( SELECT b.column column_b, c.column column_c, d.column column_d, NEW.column column_a
       FROM db1.table_b b
       JOIN db1.table_c c
       JOIN db1.table_d d
       WHERE b.id = NEW.id_b
         AND c.id = NEW.id_c
         AND d.id = NEW.id_d ) vals
JOIN db2.table_b b ON b.column = vals.column_b
JOIN db2.table_c c ON c.column = vals.column_c
JOIN db2.table_d d ON c.column = vals.column_d;


PS. Not tested, minor errors possible, check and debug.

PPS. The structure assumes that column in tables b, c and d is defined as unique.