Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 2nd, 2006, 02:08 PM
Registered User
 
Join Date: May 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Collect database space used and generate a report

I was wondering if there is a best way to collect the space used for each database, generate a weekly space utilization report, and make a comparison to the last week’s data to see the changes by percentage. Is there a sample code that I can follow?

 
Old May 8th, 2006, 01:42 PM
Authorized User
 
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to manudutt
Default

Hi !

with the following altered version of sp_helpdb you can generate db name and db size report .. then you can further alter this sp to generate reports as you want ..

-----------------
Code:
create procedure sp_getdb 
as

declare @exec_stmt nvarchar(625)
declare @name sysname
declare @low nvarchar(11)

set nocount on

create table #spdbdesc
(
        dbname sysname,
        dbsize  nvarchar(13) null,
    dbid    smallint
)

if 

select @low = convert(varchar(11),low) from master.dbo.spt_values
            where type = 'E' and number = 1

--create the table 
insert into #spdbdesc (dbname,dbid)
                        select name,dbid from master.dbo.sysdatabases

--set the collation 
select @low = convert(varchar(11),low) from master.dbo.spt_values
                        where type = 'E' and number = 1

declare ms_crs_c1 cursor for
        select db_name (dbid) from #spdbdesc
open ms_crs_c1
fetch ms_crs_c1 into @name
while @@fetch_status >= 0
begin
        --Insert row for each database
    select @exec_stmt = 'update #spdbdesc set dbsize = 
            (select str(convert(dec(15),sum(size))* ' + @low + '/ 1048576,10,2)+ '' MB'' from '+ quotename(@name, '[') + '.dbo.sysfiles) WHERE current of ms_crs_c1'
                execute (@exec_stmt)
        fetch ms_crs_c1 into @name
end
deallocate ms_crs_c1

select dbid,
    name = dbname,
        db_size = dbsize
from  #spdbdesc
order by dbid

return (0)
if you are not able to tailor made it like your descrips please tell me i will do that for you ..

>>>>>>>>>>>>>>>>

I have known a great many troubles, but most of them never happened. -- Mark Twain
 
Old May 9th, 2006, 06:14 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

well its not that simple of code but I am not sure it can be made extremely simple. Question is do you follow this???






Similar Threads
Thread Thread Starter Forum Replies Last Post
Space in my database table Access cannielynn0312 ASP.NET 1.0 and 1.1 Basics 4 December 27th, 2007 06:02 AM
How can i generate report from OLAP cube manoj_k79 Classic ASP Basics 0 January 25th, 2007 12:42 AM
How can i generate OLAP Report manoj_k79 Classic ASP Basics 0 December 15th, 2006 08:28 AM
How to generate a report using vba ? method Access VBA 1 May 3rd, 2005 04:48 AM
Crystal Report: Wanted to eliminate space if data avbabu Crystal Reports 2 November 5th, 2004 06:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.