title: How to write a stored procedure in mysql to delete records from entire tables in database using MySQL?
body: <p>I have 4 tables joined together in MySQL and now i need to write a stored procedures to delete a record from all tables by passing ID  and database name from procedure parameters dynamically. while i call my procedures it's like the below code:</p>
  
  <pre><code>CALL delete_case_fromTables('databasename',1);
  </code></pre>
  
  <p>I wrote a procedure as below, but its not what i need, but i need to delete a record from all 4 tables in a database dynamically.</p>
  
  <pre><code>DELIMITER $$
  CREATE PROCEDURE delete_cms_case_demo(IN DATABASE_NAME VARCHAR(200),IN CASE_URN INT)
  
  BEGIN
      SET @sql = CONCAT('DELETE FROM ', DATABASE_NAME,'.appellateinv WHERE case_urn= ', CASE_URN);
      PREPARE stmt FROM @SQL;
      EXECUTE stmt;
      DEALLOCATE PREPARE stmt;
  
  END$$
  </code></pre>
  
  <p>Please  Help me in this regard. Thanks</p>