SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 Reliable Method for Determining Data File Size
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jbates99
Constraint Violating Yak Guru

368 Posts

Posted - 12/25/2012 :  14:45:00  Show Profile  Reply with Quote
I want to track the size of every database's data file into a table so I can project future growth patterns.

Does anyone have a solid technique, that can be ran programatically?

Note - I don't the file size - that is how much space that's allocated. I want to find the amount of space actually used. If the data file were shrunk to minimum size, if that makes sense.

Thanks for any tips.
Jack

v_yaduvanshi
Starting Member

India
6 Posts

Posted - 12/26/2012 :  05:19:50  Show Profile  Reply with Quote
u may check this

Select db_name(),fileid,case when groupid = 0 then 'log file' else 'data file' end,
name,filename, [file_size] = convert(int,round((sysfiles.size*1.000)/128.000,0)),
[space_used] =convert(int,round(fileproperty(sysfiles.name,'SpaceUsed')/128.000,0)),
[space_left] =convert(int,round((sysfiles.size-fileproperty(sysfiles.name,'SpaceUsed'))/128.000,0))
from dbo.sysfiles;

Go to Top of Page

jbates99
Constraint Violating Yak Guru

368 Posts

Posted - 12/27/2012 :  16:56:51  Show Profile  Reply with Quote
Thank you v_ Your technique seesm to compute a size that is accurate.

This will work if I hardcode for each known database name with a preceeding Use DatabaseX;

I was hoping for a way of looping thru all databases in a stored procedure so it can automatically pick up any new databases.

Thanks for your idea. Jack
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000