Tuesday, January 27, 2009

How to Get Available space on Database

How to Get Available space on Database using a Dynamic Query:-

EXEC(N'USE ' + @dbname + N' select  [FILE_SIZE_MB] =
           convert(decimal(12,2),round(size/128.000,2)),
     [SPACE_USED_MB] =
           convert(decimal(12,2),round(fileproperty(name,''SpaceUsed'')/
128.000,2)),
     [FREE_SPACE_MB] =
           convert(decimal(12,2),round((size-
fileproperty(name,''SpaceUsed''))/128.000,2)),
     [DEVICE_NAME] = left(NAME,15)
from  dbo.sysfiles;')

No comments: