Checking database file sizes without a GUI

In: SQL Server
Written by: Taylor Gerring


19 Aug 2008

Here’s a quick little statement you can use to verify the size and growth settings for a SQL Server database. It doesn’t spell everything out for you, but if you’re aware of some common conventions (-1 = unlimited, 0 = no growth), it’s a fast and easy way to verify settings before issuing your ALTER DATABASE command. The filename is commented out by default, but provided just-in-case.

select
	  db_name() [Database]
	, name [Logical Name]
	, ceiling(size/128.0) [Size (MB)]
	, case maxsize when -1 then maxsize else ceiling(maxsize/128.0) end [MaxSize (MB)]
	, case when (status & 0x100000) = 0 then ceiling(growth/128.0) else growth end [Growth]
	, case when (status & 0x100000) = 0 then 'MB' else '%' end [% or MB]
	--, filename
from
	sysfiles

Some example output:

Database	Logical Name		Size (MB)	MaxSize (MB)	Growth	% or MB
ReportServer	ReportServer		18		-1		1	MB
ReportServer	ReportServer_log	177		2097152		10	%

And an image from SSMS to verify:
File growth in GUI

Comment Form

@TaylorGerring


Unless specified otherwise, this website is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States.
Stop SOPA
Unless specified otherwise, this website is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States.