Skip to content

Instantly share code, notes, and snippets.

@ainsofs
Created July 26, 2022 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ainsofs/8e223821f5c233bc170f4d6c5d0e0a0d to your computer and use it in GitHub Desktop.
Save ainsofs/8e223821f5c233bc170f4d6c5d0e0a0d to your computer and use it in GitHub Desktop.
Get table sizes on Ms SQL
-- DROP TABLE #tmpTableSizes
CREATE TABLE #tmpTableSizes
(
tableName varchar(100),
numberofRows varchar(100),
reservedSize varchar(50),
dataSize varchar(50),
indexSize varchar(50),
unusedSize varchar(50)
)
insert #tmpTableSizes
EXEC sp_MSforeachtable @command1="EXEC sp_spaceused '?'"
select * from #tmpTableSizes
order by cast(LEFT(reservedSize, LEN(reservedSize) - 4) as int) desc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment