Posts Tagged ‘tsql’

Posted by IsaacBlum at 6 November 2009

Category: Uncategorized

Tags: , , ,

Thanks  to http://www.pgrconsulting.com/useful_p_and_t.htm 

– Create the temp table for further querying

CREATE TABLE #temp(

            rec_id               int IDENTITY (1, 1),

            table_name       varchar(128),

            nbr_of_rows     int,

            data_space       decimal(15,2),

            index_space     decimal(15,2),

            total_size          decimal(15,2),

            percent_of_db  decimal(15,12),

            db_size             decimal(15,2))

 

– Get all tables, names, and sizes

EXEC sp_msforeachtable @command1=”insert into #temp(nbr_of_rows, data_space, index_space) exec sp_mstablespace ‘?’”,

                                    @command2=”update #temp set table_name = ‘?’ where rec_id = (select max(rec_id) from #temp)”

 

– Set the total_size and total database size fields

UPDATE #temp

SET total_size = (data_space + index_space), db_size = (SELECT SUM(data_space + index_space) FROM #temp)

 

– Set the percent of the total database size

UPDATE #temp

SET percent_of_db = (total_size/db_size) * 100

 

– Get the data

SELECT *

FROM #temp

ORDER BY total_size DESC

 

– Comment out the following line if you want to do further querying

DROP TABLE #temp

  • Archives

  • Tags

  • Subscribe
  • Pages

  • More

  • Disclaimer…

    This is my personal weblog. The opinions expressed herein are my own and are not representative of any 3rd party influence. The owner of this blog reserves the right to edit or delete any comments submitted to this blog without notice if they are deemed to be spam, offensive or otherwise inappropriate. The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.


    Lastly, I do my best to document my sources if the article is not of my own creation. If I have missed or forgotten to source your work. I would love feedback via the comments section. Thank you.

DreamHost promos
SiteLock