Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Log Table Growth

Author  Topic 

dewacorp.alliances

452 Posts

Posted - 2008-02-14 : 03:46:50
Hi guru

We have sql code below:

 CREATE TABLE #temp(
DBName varchar(128),
RecID int IDENTITY (1, 1),
TableName varchar(128),
NbrOfRows int,
DataSpace decimal(15,2),
IndexSpace decimal(15,2),
TotalSize decimal(15,2),
PercentOfDB decimal(15,2),
DBSize decimal(15,2))


EXEC sp_msforeachtable @command1="insert into #temp(NbrOfRows, DataSpace, IndexSpace) exec sp_mstablespace '?'",
@command2="update #temp set TableName = '?' where RecID = (select max(RecID) from #temp)"

UPDATE #temp
SET TotalSize = (DataSpace + IndexSpace), DbSize = (SELECT SUM(DataSpace + IndexSpace) FROM #temp)

UPDATE #temp
SET PercentOfDb = (TotalSize/DbSize) * 100

declare @DBName varchar(128)
select @DBName = db_name()

UPDATE #temp
SET DBName = @DBName

INSERT INTO Administration.dbo.dba_TableGrowth(DBName, RecID, TableName, NbrOfRows, DataSpace, IndexSpace, TotalSize, PercentOfDb, DBSize)
SELECT *
FROM #temp
ORDER BY TotalSize DESC

DROP TABLE #temp


We generally do every month run this script for each database that we have. We have Administration database that holds this info.

Now we are trying to automate this by putting into stored procedure. Ideally will loop through every single database but we found this sp_msforeachtable doesn't seem to work. How do suppose approach on this?

Thanks for the input.
   

- Advertisement -