Query to check the size of each table in a database

Sometimes the database keeps growing and you want to figure out which table(s) are causing the issue. It happens sometimes for me on Craft CMS projects.

I then find it useful to be able to isolate the largest table(s) within the database to see where the issue is at.

I've found the simplest solution being to run the following query:

SELECT tablename AS "Tables", round(((datalength + indexlength) / 1024 / 1024), 2) "Size in MB" FROM informationschema.TABLES WHERE tableschema = "yourdbname" ORDER BY (datalength + index_length) DESC;

Credits to Steve Grant at Stackoverflow: https://craftcms.stackexchange.com/questions/40236/the-size-of-the-database-has-increased-how-to-reduce-it

Storing it here for future reference, instead of always having to google it.