Sunday, November 13, 2016

How to count how many table inside a database

When first starting a project, you probably just creating a few tables inside a database, but as the project gets more mature, the application is growing and you end up having so many tables. On mysql you can count the number of tables inside a database with a special query.

Before i show you the query, first let's just show list of tables inside a database, to do this we can use mysql built in command 'show tables', simply run this command:
SHOW TABLES;

Now to count how many tables inside a database, you can use this special query:
SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'NAME_OF_THE_DATABASE';
For example the name of the database is 'office-db', so the query will be like this:
SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'office-db';

No comments:

Post a Comment