Ви можете використати і цей старомодний ...
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
DECLARE @iCount int, @iMax int, @DatabaseName varchar(200), @SQL varchar (8000)
Select NAME, DBID, crdate, filename, version
INTO
from MAster..SYSDatabASES
SELECT @iCount = Count(DBID) FROM
Select @SQL='Create Table ##iFile1 ( DBName varchar( 200) NULL, Fileid INT, FileGroup int, TotalExtents INT , USedExtents INT ,
Name varchar(100), vFile varchar (300), AllocatedSpace int NUll, UsedSpace int Null, PercentageFree int Null ) '+ char(10)
exec (@SQL)
Create Table
Name varchar(100), vFile varchar (300), AllocatedSpace int NUll, UsedSpace int Null, PercentageFree int Null )
WHILE @iCount>0
BEGIN
SELECT @iMax =Max(dbid) FROM
Select @DatabaseName = Name FROM
SELECT @SQL = 'INSERT INTO ##iFile1(Fileid , FileGroup , TotalExtents , USedExtents , Name , vFile)
EXEC (''USE [' + @DatabaseName + '] DBCC showfilestats'') ' + char(10)
Print (@SQL)
EXEC (@SQL)
SELECT @SQL = 'UPDATE ##iFile1 SET DBName ='''+ @DatabaseName +''' WHERE DBName IS NULL'
EXEC (@SQL)
DELETE FROM
Select @iCount =@iCount -1
END
UPDATE
SET AllocatedSpace = (TotalExtents * 64.0 / 1024.0 ), UsedSpace =(USedExtents * 64.0 / 1024.0 )
UPDATE
SET PercentageFree = 100-Convert(float,UsedSpace)/Convert(float,AllocatedSpace )* 100
WHERE USEDSPACE>0
CREATE TABLE
DBName varchar( 100),
LogSize float,
PrcntUsed float,
status int
)
INSERT INTO
EXEC ('DBCC sqlperf( logspace)')
INSERT INTO
select @@ServerName ,DBNAME, 'Data' as FileType,Name, vFile, PercentageFree , AllocatedSpace
from
UNION
select @@ServerName ,DBNAME, 'Log' as FileType ,DBName,'' as vFile ,PrcntUsed , LogSize
from
Select * from
select ServerName ,DBNAME, FileType, Sum( AllocatedSpace) as AllocatedSpaceMB
from
Group By ServerName ,DBNAME, FileType
Order By ServerName ,DBNAME, FileType
select ServerName ,DBNAME, Sum( AllocatedSpace) as AllocatedSpaceMB
from
Group By ServerName ,DBNAME
Order By ServerName ,DBNAME
drop table
drop table
drop table
drop table