Wednesday, 20 July 2011

'SPACE DETAILS OF DATABASES' in Sql Server

PRINT '=========================='
PRINT 'SPACE DETAILS OF DATABASES'
PRINT '=========================='
EXEC sp_msforeachdb @command1="use ? exec sp_spaceused"

PRINT '=========================='
PRINT '     DATABASE DETAILS     '
PRINT '=========================='
SET NOCOUNT ON
DECLARE NM CURSOR LOCAL STATIC FOR
SELECT NAME FROM SYSDATABASES
DECLARE @DN VARCHAR(50)
DECLARE @CMD1 NVARCHAR(4000)
PRINT ''
OPEN NM
FETCH NEXT FROM NM INTO @DN
WHILE @@FETCH_STATUS=0
BEGIN
print 'DB Details ' + @DN
set @CMD1='select CONVERT(VARCHAR(35), a.name)Name,CONVERT(VARCHAR(8),filegroup_name(a.groupid)),(a.size * 8)total_size ,b.spaceused from '+@DN+'..sysfiles a, ( select groupid, sum(reserved) spaceused from '+@DN+'..sysindexes where indid in (0,1,255) group by groupid ) b   where a.groupid = b.groupid'
EXEC SP_EXECUTESQL @CMD1
FETCH NEXT FROM NM INTO @DN
END
CLOSE NM
DEALLOCATE NM
GO

No comments:

Post a Comment