I'm trying to automate some trivial maintenance tasks for my own
MySQL server, and trying also to minimize the effort, so ... Here
is the recipe:
Take an excellent generalized stored procedure like the one by
Konstantin Osipov, see "Dynamic SQL is Stored Procedures" on MySQLForge
(example 4).
Tune it a bit so that it takes into account only non system
tables (I'm trying to turn it into something similar to
Microsoft's sp_MSforeachtable), here is the code:
- DELIMITER $$
- DROP PROCEDURE IF EXISTS `test`.`sp_4_each_table` $$
- CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_4_each_table`(db_name VARCHAR(64), template VARCHAR(21845))
- BEGIN
- #
- DECLARE done INT DEFAULT 0;
- #
- DECLARE tname VARCHAR(64);
- #
- DECLARE c …