LoginSignup
1

More than 3 years have passed since last update.

レコード件数の多い順でソートしてテーブル一覧を取得するSQL

Posted at

MySQLを使用したアプリケーションで運用していると
「あー、データ量増えてきたなー」
「テーブルのレコード数が多いテーブルってどのテーブルで何件あるんだろう?」
って時があります。

そういう時にinformation_schemaからテーブルのレコード数が多い順にソートして取得するSQLです。

select table_name, table_rows from information_schema.TABLES order by table_rows desc;

limitで絞ればレコード数上位10テーブルとかも取得できます。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
1