Register  Login  
  May 18, 2012  
Search_Blog Minimize
Print  

Blog_Archive Minimize
Print  

Blog    
View_Blog Minimize
Jun 4

Written by: host
Thursday, June 04, 2009 8:28 PM 

Unless you are hosting your site on your own server(s), your hosting company will impose a limit on your disk space.  Occasionally, you will see a posting in the DotNetNuke forums asking "Why is the database so big?" or "What table is using all the disk space"

So there is two ways to look at this ... via SQL Servier Management Studio (SSMS) or via SQL ... some hosting environments do not allow access via SSMS, so SQL is the only option. 

The following SQL will display all the tables:

 EXECUTE sp_MSforeachtable 'EXECUTE sp_spaceused [?]'

This statement uses the "hidden" Microsoft store procedure "sp_MSforerachtable" that will execute a given command against each table in a database.  You will need to review the results to determine the largest table.

Alternatively,  the following T-SQL will generate a list of tables in largest row count to smallest.


set nocount on

-- create table to hold name and rows
-- cannot use in-memory as it will not work with sp_MSforeachtable
Create table #dnntables (
 tablename varchar(64),
 tablerows int
)

  declare @rows int
 declare @sql varchar(1000)

-- load table with names
-- undocumented MS stored proc -- well documented on Google
exec sp_MSforeachtable  'insert into #dnntables(tablename) values( ''?'')'

-- create cursor to load rows count into table
declare tabcursor cursor read_only
for select tablename from #dnntables

declare @Tablename varchar(64)

open tabcursor

fetch next from tabcursor into @TableName
while (@@fetch_status <> -1)
  begin
   set @sql = 'update #dnntables '
   set @sql = @sql + 'set tablerows = (select count(*) from ' + @TableName + ')'
   set @sql = @sql + 'where tablename = ''' + @TableName + ''''
  
   --print @sql     -- uncomment to see generated update command
 
   exec (@sql)      -- note: must enclose in brackets to executed string

 fetch next from tabcursor into @TableName
  end

-- dump collected data
--Select * from #dnntables
Select * from #dnntables where Tablerows > 0 order by TableRows desc

-- clean up
close tabcursor
deallocate tabcursor

drop table #dnntables
go 

The routine aslo uses the sp_MSforeachtable routine.

Hope these help
Paul.

Tags:

2 comment(s) so far...

ugg boots usa

I agree with you! very valuable post. and here i have a ugg boots usa shop which i recommend to all of you,we carry ugg handbags such as ugg grab bags and classic stylish like ugg bailey button black, ugg bailey button sand, and ugg bailey button grey, ugg bailey button eggplant,and ugg bailey button chocolate,are the most popular items, also such as the tall boot like ugg bailey button triplet sand, ugg bailey button triplet grey, and ugg bailey button triplet chestnut,i prefer this two ugg bailey button triplet chocolate,and ugg bailey button triplet black,we still carry cardy boots like ugg classic cardy grey, ugg classic cardy cream and ugg classic cardy black.they are good for spring and fall.there are still mini boots like ugg classic mini sand, ugg classic mini grey,and ugg classic mini chocolate,for stylish wear.i think ugg classic mini chestnut, and ugg classic mini black,is your first choice.we still have the most classic boots ugg classic short sand, ugg classic short fancy chestnut,and ugg classic short fancy grey are the most classic short boots,also available in ugg classic short grey and ugg classic short fuschia for ultra comfortable,you could choose ugg classic short eggplant, ugg classic short chocolate and ugg classic short chestnut are the excellent choices,ugg classic short aqua,and ugg classic short black are the most popular item.if you are going outside,ugg ultra short sand, ugg ultra short chocolate comes in a short style.ugg ultra short chestnut and ugg ultra short black will be your first choice,we still carry tall boot style like ugg ultra tall chocolate,ugg ultra tall chestnut,and ugg ultra tall black,they feature with rubber outsole,ideal for outdoor sport,my favorite is ugg ultra tall sand,there are another cold weather boots like ugg sundance ii black, ugg sundance ii chocolate and ugg sundance ii chestnut. they are all brand new style, also carry ugg nightfall sand, ugg nightfall chocolate.welcome to www.thepopshoes.com. free shipping and fast delivery.order yours today.!!!!

By muichan on   Wednesday, May 02, 2012 10:14 PM

Coach Factory Outlet

Some bags sold at Coach Factory Outlet will have small defects. These defects are made during the process of Coach Outlet Online. But these defects are very small. No body will notice Coach Outlet. In case you buy some bags which you will not like in the future, it is better for you to check the quality before you make the payment.Of course, if you think fake Coach Factory are much cheaper and you can accept them. You can buy some of them on Internet. There are plenty of these Coach Factory Outlet there
Ladies are creatures of Coach Factory Store. They are born to love designer bags. Sometimes they can not Coach Outlet. They can not stop buying their Coach Factory there are very little money in their wallets. They know they should not do that. But a Coach Outlet Store Online will definately show her personality and Coach Outlet Online. Just like people will love Coach Outlet Store, women can not say no to Coach Outlet Online.

By michaelkors on   Tuesday, May 15, 2012 4:25 AM

Blog_List Maximize
Print  

  Home | Blog | Forum | Subscriptions | Free Modules | Videos   Page generated in 0.234957 seconds.
  Copyright 2010 by TressleWorks   Terms Of Use | Privacy Statement