Posted By

pauliehaha on 04/02/09


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

sulfurito
flurk118


Table Size


 / Published in: SQL
 

  1. CREATE PROCEDURE [dbo].[GetDBTableSize]
  2. AS
  3. BEGIN
  4. SET NOCOUNT ON;
  5. DECLARE @cmdstr varchar(100)
  6. --Create Temporary Table
  7. CREATE TABLE #TempTable
  8. ( [Table_Name] varchar(50),
  9. Row_Count int,
  10. Table_Size varchar(50),
  11. Data_Space_Used varchar(50),
  12. Index_Space_Used varchar(50),
  13. Unused_Space varchar(50)
  14. )
  15. --Create Stored Procedure String
  16. SELECT @cmdstr = 'sp_msforeachtable ''sp_spaceused "?"'''
  17. --Populate Tempoary Table
  18. INSERT INTO #TempTable EXEC(@cmdstr)
  19. --Determine sorting method
  20. SELECT * FROM #TempTable ORDER BY Table_Name
  21. --Delete Temporay Table
  22. DROP TABLE #TempTable
  23. END

Report this snippet  

You need to login to post a comment.