What's the size of my TFS Databases?

How many times have you been caught trying to figure out what is the current size of your TFS databases? I find more often than not, just before a TFS Migration or a backup procedure, this is a very frequent ask. Here's a nifty T-SQL Script to get your answer.

 

/*
==============================================
-- Please use judiciously as Microsoft does not recommend you directly hitting the DB
-- Determine the size of MS SQL Server Database
-- This is especially useful to determine how much space you need for backup/migration etc.
==============================================
*/

SELECT DB_NAME(database_id) AS [Database Name],
[name] [Logical File Name],
physical_name [Physical File Location],
CASE [type_desc] WHEN 'ROWS' THEN 'DATA'
WHEN 'LOG' THEN 'LOG'
END AS [Database File Type],
(size * 8) / 1024 [Database Size (MB)]
FROM sys.master_files
WHERE DB_NAME(database_id) LIKE 'tfs_%'
ORDER BY 1

/*=============== ALL DONE! ===============*/

 

Keep it handy for other systems why don't ya :-)