开发者

MySQL Tables and row count

I am trying to get a list of tables and their number of rows. I have been using this query:

SELECT TABLE_NAME, TABLE_ROWS 
FROM INFORMATION_SCHEMA WH开发者_如何转开发ERE TABLE_SCHEMA = 'myDatabase'

I am finding this sometimes returns null. What I would like to do is catch this probably doing something similar to

IFNULL ( TABLE_ROWS, SELECT COUNT(*) FROM ????)

Only I'm not sure what I should enter for ????

how to make it dynamic based on the TABLE_NAME column?.

Edit: Additional information: I found that the 'tables' not displaying are actually views.


Might as well do

SHOW TABLE STATUS FROM YOUR_DATABASE;

It always return a column named as Rows which is number of rows in that table.


From the documentation:

The TABLE_ROWS column is NULL if the table is in the INFORMATION_SCHEMA database.

So, you will propably not need it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜