Reputation: 485
Does anyone know what MySQL statement I would use to return results containing a list of all the tables in a database and the number of rows in each one?
Upvotes: 1
Views: 1365
Reputation: 15118
I'm learning MySQL and didn't know about the show table status command. Nice One!
As I said, I'm just starting, but already my database has over 2 million rows.
Does the host computer have to find storage for all rows if you
select * from table_name
Wouldn't it be simpler to say
select count(*) from table_name
and get only one row in return?
Upvotes: 0
Reputation: 136391
try this
SELECT Table_name,Table_rows FROM
information_schema.tables
WHERE TABLE_SCHEMA = 'yourdatabase'
Upvotes: 8
Reputation: 94635
Use PEAR DB shortcuts methods.
$db=DB::Connect("mysql://root@localhost/testdb");
$tab=$db->getListOf("tables");
....
$db->tableinfo("table_name");
...
$r=$db->query("select * from table_name");
echo $r->numrows();
echo $r->numcols();
Upvotes: 0
Reputation: 4143
show tables - for list of tables
show table status - should give you the name, number of rows, and a list of extra info
Upvotes: 3