Last active
June 10, 2022 10:05
-
-
Save NaserKhoshfetrat/2df1beaf4247b918bc0232c5d06372fe to your computer and use it in GitHub Desktop.
sql server procedure TableSpaceUsed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--<sys.sp_MSforeachtable>: execute sp_spaceused for all of database table | |
--<sp_spaceused>: return rows, index size and data size of table | |
EXEC sys.sp_MSforeachtable 'sp_spaceused ''?'''; | |
--or as table | |
USE [Fabrics] | |
GO | |
CREATE TABLE #TableSpaceUsed( | |
[name] [nvarchar](120) NULL, | |
[rows] [nvarchar](120) NULL, | |
[reserved] [nvarchar](120) NULL, | |
[data] [nvarchar](120) NULL, | |
[index_size] [nvarchar](120) NULL, | |
[unused] [nvarchar](120) NULL | |
) ON [PRIMARY] | |
Insert Into #TableSpaceUsed | |
EXEC sys.sp_MSforeachtable 'sp_spaceused ''?'''; | |
Select * from #TableSpaceUsed | |
Order by CAST([rows] as int) desc | |
Drop table #TableSpaceUsed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment