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.




Data | BI Engineer (Microsoft Stack)

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Airdrop: MangoSwap Deposit Farming Event

Introducing Descript

Connecting Python and Java with Rust

Maximum Subarray

Announcement on the migration of NFTMart telegram group

Architecture documentation and Architecture Description Languages

git clone private repository — An easy solution

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Michal Molka

Michal Molka

Data | BI Engineer (Microsoft Stack)

More from Medium

SQL Server Installation using Configuration File

SQL Server Partitioning : What is it? When to use it? When not to use it?

SQL Query optimization Techniques

Normalization in Database