I have a huge database with hundreds of tables and I want to find out the total fields (columns) defined in all of the tables.
Is there a sql query that can give me that? If not, what would be the best way?
To get total number of fields in all tables in database, you can use information_schema. columns along with aggregate function count(*).
To check the count of tables. mysql> SELECT count(*) AS TOTALNUMBEROFTABLES -> FROM INFORMATION_SCHEMA. TABLES -> WHERE TABLE_SCHEMA = 'business'; The following output gives the count of all the tables.
Is this what you want?
select count(*)
from information_schema.columns
where table_schema = 'your_schema'
You can run it like this to see if it is reasonable:
select table_name, column_name
from information_schema.columns
where table_schema = 'your_schema'
order by 1, 2
Try this (while logged into your current schema):
select count(*) from information_schema.columns where table_schema = DATABASE();
I am new in mysql but if table information_schema.columns is the table with table_name and column_name information then you can use following query
select table_name, count( distinct column_name ) column_number_used
from information_schema.columns
where table_schema = 'your_schema'
group by table_name
this should give all table names with respective column number used in that table..
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