Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)
edited by

I can execute the following query to get the sizes of all the tables in a MySQL database:

show table status from myDatabaseName;

I want some help in understanding the results. I am looking for tables with the largest sizes.

Which column should I be looking at?

1 Answer

0 votes
by (12.7k points)
edited by

You can use the following query to display the size of a table (however you have to substitute the variables first):

SELECT 
    table_name AS `Table`, 
    round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB` 
FROM information_schema.TABLES 
WHERE table_schema = "$DB_NAME"
    AND table_name = "$TABLE_NAME";

or you can also this below query to list the size of every table in each database, largest first:

SELECT 
     table_schema as `Database`, 
     table_name AS `Table`, 
     round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB` 
FROM information_schema.TABLES 
ORDER BY (data_length + index_length) DESC;

Are you interested to learn SQL in detail? Join this SQL Training course by Intellipaat.

Related questions

0 votes
1 answer
asked Dec 25, 2020 in SQL by Appu (6.1k points)
0 votes
2 answers
0 votes
1 answer
asked Oct 31, 2019 in SQL by chandra (29.3k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...