Get the size of your tables

Get the size of your tables

Recently my boss asked me, why the databases (Microsoft SQL Server 2005) of our customers are so big. With the following SQL-Statements I could give more or less an answer to my boss.

name varchar(255),
rows int,
reserved varchar(255),
data varchar(255),
index_size varchar(255),
unused varchar(255)

EXEC sp_MSforeachtable @command1="INSERT INTO PW_SPACE EXEC sp_spaceused '?'"

select * from PW_SPACE order by rows desc

select sum(rows) as Rows,
convert(varchar(255), sum(convert(int, substring(data,0,len(data)-2)))) + ' KB' as Data,
convert(varchar(255), sum(convert(int, substring(index_size,0,len(index_size)-2)))) + ' KB' as Indexsize

2 thoughts on “Get the size of your tables

  1. You know, the thing about SQL is, that there is virtually nothing that can replace it.

    Does anyone know if a substitute exists for sql? I mean besides MS SQL and Oracle and all that jazz. Thanks.

  2. This won’t do it. Probably most of your space is in the logs. You need to add that to the list of the space. But this is a good start.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.