Technical Article

Database Growth Details

,

Determine the rate of database growth over a period.

Create Database DB_Administration
GO
-- Create Table to store info
CREATE TABLE [dbo].[GrowthDetails](
[Name] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Filename] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Size (MB)] [int] NULL,
[Timestamp] [datetime] NULL
) ON [PRIMARY]
GO

-- Add to a  SQL agent job and schedule to run nightly
set nocount on
declare @dbname varchar(255)

declare dblist_cursor cursor
for select name
from sys.databases
where name NOT IN ('model', 'AdventureWorksDW', 'AdventureWorks', 'tempdb','master','msdb','DB_Administration')

open dblist_cursor

fetch next from dblist_cursor into @dbname

while @@fetch_status = 0
begin

Exec('Use ' + @dbname + ' insert into DB_Administration.dbo.growthDetails 
([Name], [Filename], [Size (MB)],[Timestamp])
select [name], [filename], [size] , getdate() from sys.sysfiles')
fetch next from dblist_cursor into @dbname

end
deallocate dblist_cursor

--Stored proc to query db
CREATE procedure usp_DBGrowthDetails as
select [name], [filename], ([Size (MB)]/1024) as [Size (MB)] , [Timestamp] from dbo.growthDetails
order by [Name], [Size (MB)]  desc

-- Retrieve records
Exec usp_DBGrowthDetails

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating