Get all tables with sizes in SQL Database


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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: