mysql 檢視資料庫中所有表的記錄數

2022-09-14 15:21:21 字數 750 閱讀 8593

mysql使用select count(*) from table_name可以查詢某個表的總記錄數。想快速的知道資料庫中所有表的記錄數資訊怎麼辦?如果使用mysql的版本在5.0及以上,可以通過查詢information_schema庫中的tables表來獲取,該表中使用table_rows記錄表的行數資訊。例如檢視庫testdb中所有表的記錄數:

use information_schema;

select table_name,table_rows from tables

where table_schema = 'testdb'

order by table_rows desc;

不過需要注意的是,對於innodb表,table_rows行計數僅是大概估計值。

另外一種辦法還是借助information_schema庫的tables表,來拼接出乙個條sql語句,例如:

use information_schema;

select concat(

'select "',

table_name,

'", count(*) from ',

table_schema,

'.',

table_name,

' union all'

) from tables

where table_schema='testdb';

把生成的結果手動加工一下就行了,起碼比一張張表去拼寫要來的快。

mysql 檢視資料庫中所有表的記錄數

mysql使用select count from table name可以查詢某個表的總記錄數。想快速的知道資料庫中所有表的記錄數資訊怎麼辦?如果使用mysql的版本在5.0及以上,可以通過查詢information schema庫中的tables表來獲取,該表中使用table rows記錄表的行數...

mysql 檢視資料庫中所有表的記錄數

mysql 使用select count from table name可以查詢某個表的總記錄數。想快速的知道 資料庫中所有表的記錄數資訊怎麼辦?如果使用 mysql 的版本在5.0及以上,可以通過查詢 information schema 庫中的tables表來獲取,該表中使用table rows...

檢視Django資料庫中所有的表和刪除表操作

django建立web程式後,中途你為某個模型新增了字段或者修改了字段,你希望把該錶刪除了,重新執行makemigrations migrate。你可以直接進入dbshell介面,直接刪除表。具體操作如下 進入命令列介面,切換到manage.py所在的目錄 python manage.py dbsh...