This weekend I had to find a way to calculate the size (on disk) of a MS SQL Sever database. I got two solutions, both of which worked great. The first solution came from one of my coworkers, Dave An:
SELECT (size * 8) as filesize, filename from sysfiles
This returned the size of both the main data file and the log file. Dave made sure to mention that this assumes a default setting for the database page size.
Another solution was provided by Jared Riley:
<CFSTOREDPROC DATASOURCE=”yourdatasource” PROCEDURE=”sp_helpdb” RETURNCODE=”Yes”>
CFOUTPUT QUERY = RS1>
#name# #ReplaceNoCase(db_size, “ MB”, “”, “ALL”)# #owner# #created#
This returns the complete size of the db, i.e., the data and log file combined.