0

How could I get the count of rows from each table in a certain DB including the tables name? I know how to get the table count and the sum of rows for all tables, but not how to get the count for each table separately.

3 Answers 3

1

You could try something like this:

SELECT TABLE_ROWS, TABLE_NAME
     FROM INFORMATION_SCHEMA.TABLES 
     WHERE TABLE_SCHEMA = 'DB_NAME'
Sign up to request clarification or add additional context in comments.

Comments

0

If all the tables are inside a single database, let's assume it to be "test123", then you can use the following command to fetch number of rows:

SHOW TABLE STATUS 
FROM `test123`;

It'll return result containing the following values:

`Name`, `Engine`, `Version`, 
`Row_format`, `Rows`, `Avg_row_length`, 
`Data_length`, `Max_data_length`, `Index_length`, 
`Data_free`, `Auto_increment`, `Create_time`, 
`Update_time`, `Check_time`, `Collation`, 
`Checksum`, `Create_options`, `Comment`

Comments

0

I think this query resolve your problem:

SELECT ‘table1’, (SELECT COUNT() FROM Table1) AS CountTable1, ‘table2’, (SELECT COUNT() FROM Table2) AS CountTable2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.