Skip to content

Instantly share code, notes, and snippets.

@ThabetAmer
Created November 22, 2021 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThabetAmer/bcb83c3810323207aa10c91a7136f019 to your computer and use it in GitHub Desktop.
Save ThabetAmer/bcb83c3810323207aa10c91a7136f019 to your computer and use it in GitHub Desktop.
SQL query to list numbers of rows in each table in a db schema
# tested on Mysql 5.7-8
# set database schema name to run against
SET @db_name = "DBNAME";
# actual query, two columns resulted: table name and its rows count
SELECT
TABLE_NAME,
SUM(TABLE_ROWS) as c
FROM
INFORMATION_SCHEMA.TABLES
WHERE
TABLE_SCHEMA = @db_name
group by
TABLE_NAME
order by
c;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment