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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

Constraint Violating Yak Guru

396 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.

Starting Member

11 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(,'SpaceUsed')/128.000,0)),
[space_left] =convert(int,round((sysfiles.size-fileproperty(,'SpaceUsed'))/128.000,0))
from dbo.sysfiles;

Go to Top of Page

Constraint Violating Yak Guru

396 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  
 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.02 seconds. Powered By: Snitz Forums 2000