Monday, September 15, 2008

Counting the tables in MySQL Database

Finding ou how cool MySQL is, I gathered this statement that might be useful when doing a CLI tasks.

select count(*) as number_of_tables from information_schema.tables WHERE table_schema='schema_name';

OR

select count(*) as number_of_tables from information_schema.tables WHERE table_schema='schema_name' and table_type = 'BASE TABLE';


The latter one does only selects those base tables, BASE TABLE is actually a MySQL valid value of a table_type. This link can give some information about schema -> http://dev.mysql.com/doc/refman/5.0/en/information-schema.html