Skip to content

Instantly share code, notes, and snippets.

@rochefort
Created April 26, 2014 21:18
Show Gist options
  • Save rochefort/11331368 to your computer and use it in GitHub Desktop.
Save rochefort/11331368 to your computer and use it in GitHub Desktop.
delimiter //
DROP PROCEDURE IF EXISTS all_tables_count//
CREATE PROCEDURE all_tables_count(
IN schemaName VARCHAR(100)
)
BEGIN
DECLARE done INT;
DECLARE _tableName VARCHAR(100);
DECLARE cur CURSOR FOR
select TABLE_NAME from information_schema.tables where TABLE_SCHEMA = schemaName order by TABLE_NAME;
DECLARE EXIT HANDLER FOR NOT FOUND SET done = 0;
SET done = 1;
OPEN cur;
WHILE done DO
FETCH cur INTO _tableName;
SET @s = CONCAT('SELECT \'', _tableName, '\', COUNT(*) FROM ', _tableName);
PREPARE stmt from @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END WHILE;
END
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment