Search This Blog & Web

Wednesday, October 21, 2009

Finding used table space with data

Following script used to find each table space used in database along with data. This script is using a master procedure to find this.

Very helpfull and picked from a fourm post.

Create Table #temp (
table_name sysname ,
row_count int,
reserved_size varchar(50),
data_size varchar(50),
index_size varchar(50),
unused_size varchar(50))

SET NOCOUNT ON
insert #temp exec sp_msforeachtable 'sp_spaceused ''?'''

select a.table_name,
a.row_count,
count(*) as col_count,
a.data_size
from #temp a
inner join information_schema.columns b on a.table_name = b.table_name
group by
a.table_name, a.row_count, a.data_size
Order by CAST(Replace(a.data_size, ' KB', '') as integer) desc
drop table #temp

3 comments:

Anonymous said...

It is very helpful for me. I got solution of my problem that i cannot find previous 2 weeks.

Anonymous said...

Helped me

Anonymous said...

Its a very good article. I think only this query will help alot..
sp_msforeachtable 'sp_spaceused ''?'''