Get MS SQL Database Table Sizes

In this example we will get the sizes of each table within an Microsoft SQL database. We do this by creating a temporary table and then running the stored procedure sp_MSforeachtable to call the stored procedure sp_spaceused, insert the output into the temporary table and then select the results.


CREATE TABLE tmp_TableSizes
(
name SYSNAME,
rows int,
reserved varchar(10),
data varchar(10),
index_size varchar(10),
unused varchar(10)
)
 
INSERT tmp_TableSizes
EXEC sp_MSforeachtable 'sp_spaceused ''?'''
 
SELECT * FROM tmp_TableSizes ORDER BY name
 
DROP TABLE tmp_TableSizes



Comments

No comments yet.

Add Yours

  • Author Avatar

    YOU


Comment Arrow




About Author

Robert

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning hands down.