title: Create Trigger inside stored procedure in mysql
body: <p>I want to create an trigger inside an procedure. but after some research I got to know that it is not possible. can u suggest me another way I can achieve the below actions. (I cant share exact data and queries due to some reason. please refer similar queries.)</p>
  <p><em><strong>What I want</strong></em></p>
  <p>I have created an temporary table containing data i need. <br>
  eg. <code>CREATE TEMPORARY TABLE temp1 SELECT id, col_1 FROM table1 WHERE col_1=2;</code></p>
  <p>I want to inset data in table <code>table2</code> when data is inserted in temp1, which i can achieve by creating a <code>TRIGGER</code>. but the problem is I want to give a value in <code>table2</code> which will be dynamic and will be taken from nodejs backend. so i created a <code>PROCEDURE</code> which takes parameter <code>neededId</code>. but i cant created trigger inside a procedure. is their any other way i can achieve this?</p>
  <p><em><strong>Procedure I Created</strong></em></p>
  <p><em>here <code>neededId</code> is the foreign key I get from backend to insert</em></p>
  <pre><code>
  DELIMITER $$
  USE `DB`$$
  CREATE PROCEDURE `MyProcedure` (IN neededID int)
  BEGIN
      DROP TABLE IF EXISTS temp1;
      CREATE TEMPORARY TABLE temp1 SELECT id, col_1 FROM table1 WHERE col_1=2;
  
      
      DROP TRIGGER IF EXISTS myTrigger;
      CREATE TRIGGER myTrigger AFTER INSERT ON temp1 FOR EACH ROW
      BEGIN
          INSERT into table2(&quot;value1&quot;, &quot;value2&quot;, neededId);
      END;
      
  END$$
  
  DELIMITER ;
  
  </code></pre>