Wednesday 3 September 2008

Databases File Size [Trend Analysis] : SQL 2005 Script

Here is the script that is useful for to capture Databases File Sizes required for Trend Analysis:
/****
CREATE DATABASE TREND
USE TREND

IF OBJECT_ID('DatabaseFiles') IS NULL
BEGIN
SELECT TOP 0 file_id, name, physical_name, size*1.0/128 as [size in mbs], max_size, max_size*1.0/128 as [max_size in mbs],
growth, growth*1.0/128 as [growth in mbs], is_percent_growth INTO DatabaseFiles
FROM sys.database_files
ALTER TABLE DatabaseFiles
ADD CreationDate DATETIME DEFAULT(GETDATE())
END


EXECUTE sp_msforeachdb 'INSERT INTO DatabaseFiles SELECT file_id, name, physical_name, size*1.0/128 as [size in mbs], max_size, max_size*1.0/128 as [max_size in mbs],
growth, growth*1.0/128 as [growth in mbs], is_percent_growth, GETDATE() from [?].sys.database_files'


SELECT * FROM DATABASEFILES

*****/

You can create a scheduled job and include execute script to run once in a week and once you collected 3-6 months data, then you can export the necessary fields to Excel and using pivot table wizard you can do trend analysis.

No comments: