Summarize all table row-counts in a single query

 

DELIMITER $$

USE `evoke`$$

DROP PROCEDURE IF EXISTS `getcount`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `getcount`()
BEGIN

SET SESSION group_concat_max_len = 1000000;

SET @sql = NULL;
SET @dbname = DATABASE();

SELECT
  GROUP_CONCAT(
    CONCAT (
      'SELECT ''',TABLE_NAME,''' as TableName, COUNT(*) as RowCount FROM ',
       TABLE_NAME, ' '
    )
    SEPARATOR 'UNION ' 
  ) AS Qry
FROM
  information_schema.`TABLES` AS t
WHERE
  t.TABLE_SCHEMA = @dbname AND
  t.TABLE_TYPE = "BASE TABLE"
ORDER BY
  t.TABLE_NAME ASC

INTO @sql
;

PREPARE stmt FROM @sql;

EXECUTE stmt;

    END$$

DELIMITER ;