There is a simple task: when adding a new row to a table of one database, insert the same row into the table of another database.

A query was written: ...

delimiter // create trigger test after insert on bd1.test1 for each row begin insert into bd2.test2 set test2.first_1 = NEW.test1.first_1; set test2.second_1 = NEW.test1.second_1; set test2.third_1 = NEW.test1.third_1; end// 

... but then error 1046 (no db selected) occurs. If before the column names to clarify the base in which they are located, the system swears at the unexpected point.

Tell me how to implement the necessary request? @

  • @AlexanderPetrov Oh, no. Sorry for this misstep) - Violofan

1 answer 1

 CREATE TRIGGER test AFTER INSERT ON bd1.test1 FOR EACH ROW INSERT INTO bd2.test2 SET bd2.test2.first_1 = NEW.first_1, bd2.test2.second_1 = NEW.second_1, bd2.test2.third_1 = NEW.third_1; 

And override DELIMITER is not required.

enter image description here

  • The same error: no db selected ( - Violofan 6:09 pm
  • Everything is working. See screenshot. Perhaps you didn’t do USE bd1 before creating the trigger? - Akina
  • Yes indeed. Just flew out of my head that the need to switch the base. Thank you very much)) - Violofan