SQL Server — Table size sp_msforeachtable
Sometimes we need information about a table size or number of rows. We can use sp_spaceused stored procedure.
USE StackOverflowexec sp_spaceused 'dbo.Posts'
But if we need information about every table in a database? We can use undocumented sp_msforeachtable stored procedure along with previous one.
sp_msforeachtable 'exec sp_spaceused [?]'
To improve readability we can insert result into a table, format values and change the size from KB to MB.
Here is an example.
Here is concised and more legible summary.