Posted By

abstraktor on 04/17/11


Tagged

sql


Versions (?)

alle Tabellen eines bestimmten Musters aus einer Datenbank löschen


 / Published in: MySQL
 

droptableslike(pattern, db)

  1. USE osamos2;
  2. delimiter $$
  3. CREATE PROCEDURE drop_tables_like(pattern VARCHAR(255), db VARCHAR(255))
  4. BEGIN
  5. SELECT @str_sql:=CONCAT('drop table ', group_concat(table_name))
  6. FROM information_schema.tables
  7. WHERE table_schema=db AND table_name LIKE pattern;
  8.  
  9. prepare stmt FROM @str_sql;
  10. execute stmt;
  11. DROP prepare stmt;
  12. END$$
  13.  
  14. CALL drop_tables_like('ALT_%', 'osamos2')$$
  15.  
  16. DROP PROCEDURE if EXISTS drop_tables_like$$
  17. delimiter ;

Report this snippet  

You need to login to post a comment.