Size of a SQL Server DB

This post is more than 2 years old.

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:


#name# #ReplaceNoCase(db_size, " MB", "", "ALL")# #owner# #created#

This returns the complete size of the db, i.e., the data and log file combined.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for HERE Technologies. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA