Quickly view used space for databases in SQL 2005

You will notice that in SQL 2005, many of the features you have grown to love are missing, or changed.  If you want to be able to view the free space left in database files, you can run the following code in the context of your database:


CREATE PROCEDURE dbo.usp_ShowAvailableSpace 
AS

SELECT name AS NameOfFile,
size/128.0 -CAST(FILEPROPERTY(name, 'SpaceUsed' )AS int)/128.0 AS AvailableSpaceInMB
FROM dbo.SYSFILES
GO

Then execute:

EXEC usp_ShowAvailableSpace
In the results box you'll find the free space left in the database.  Notice that this only applies to the current database.
Your rating: None