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

Rancher 2.3 on Windows 10 with Minikube and Helm

https://t.me/EYWA_protocol_bot?start=1616112764

What is Feature Detection?

Performance Programming: Threading and Resource Sharing.

IDORs (Insecure Direct Object Reference) over Fortify Software Security Center (SSC) 17.10,

Intune Win32 App Deployment Failed. Not Applicable

PDF Download>< Expert Advisor Programming for Meta

How to build a serverless clone of Imgur using Amazon Rekognition and DynamoDB

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

How to make dynamic database name in SQL queries?

5 Lines of Code: Pandas DataFrame to SQL Server

Minimal APIs in .NET 6: how to use it to enrich data for analytics — Part1