I would like to know how many rows are in each table in my database. I've come so far as to having
select count(*) _tablename_;
However i would need to do that on each and every table - and there are a lot. What would me the best way to get a print-out with the table name and it's row count?
To get the count of rows, you need to use information_schema. tables. The syntax is as follows. SELECT table_name, table_rows FROM INFORMATION_SCHEMA.
This can be achieved by using the following query. SELECT table_schema, SUM(row_count) AS total_rows FROM ( SELECT table_schema, count_rows_of_table(table_schema, table_name) AS row_count FROM information_schema.
Use the COUNT aggregate function to count the number of rows in a table. This function takes the name of the column as its argument (e.g., id ) and returns the number of rows for this particular column in the table (e.g., 5).
SELECT table_name, table_rows FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '<your db>';
I also hope you realise there's an error in your query: it's missing a FROM
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With