Calculate the table size and number of rows

by Vishwa 1. June 2007 08:42

At some point you might need to know, how many tables you have in database, number of rows in each table, size of table and indices. Following is a simple SQL Script which can provide you a snapshot of all such details.


 Declare @TabName Varchar(100)

Create table #TempTable (Name varchar(100), Rows int,Reserved varchar(25),Data varchar(25),Index_size varchar(25),Unused varchar(25))
 
Declare TableList cursor LOCAL FAST_FORWARD FOR     
SELECT Name FROM sysobjects
WHERE xtype='U'
ORDER by Name
OPEN TableList     
     
FETCH NEXT FROM TableList INTO @TabName         
WHILE @@fetch_status = 0        
 BEGIN   
        INSERT INTO #TempTable Exec sp_spaceused @TabName
        FETCH NEXT FROM TableList INTO @TabName   
 End
CLOSE TableList
DEALLOCATE TableList
SELECT * FROM #TempTable

Tags:

SQL

Comments (2) -

shubhavani
shubhavani India
6/2/2007 7:39:52 AM #

useful procedure. Thanks.

Michal Ditto
Michal Ditto United States
9/4/2010 9:20:56 AM #

I've long read any weblogs anymore simply because as well a lot of websites had been either uninteresting or not recent. Or at worst, each. Here it can be unique, the website is thrilling and informative. Thank god you will discover still such sites for the net. Then yet again it can be really worth browsing.

Comments are closed

About Me

Me Hello,my name is
Vishwa Mohan Kumar, PMP
MCP SOA Certified Architect
I am a Software Architect. This blog is result of my experiments.

Flickr Photos

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar

Archive

Recent Comments

Comment RSS

Live Traffic Feed