Wednesday, October 23, 2013

TSQL to find database size

Earlier today I had the need to calculate both the size of my SQL database files as well as the amount of used space in the aforementioned database files. While I was at it I added a percent used column. I found lots of posts out there some horribly complicated and some way too simple and not providing enough detail.

The FILEPROPERTY (http://technet.microsoft.com/en-us/library/ms188401.aspx) was the key here and what I used to simply calculate the amount of space used within the database files.

Also make sure you replace the "<your_database_name_here>" at the beginning of the query or make sure you have the appropriate database selected in SSMS.

No comments: